Skip to content

Pre-commit unable to determine if it is in a container from /proc/1/cgroup for Docker-in-Docker setups #3360

@JasonAlt

Description

@JasonAlt

search you tried in the issue tracker

is:issue docker is:open

describe your issue

Developing in a Fedora 40 container on a Fedora 41 host, using Docker-in-Docker such that pre-commit can make use of existing containers for lint tests. It appears that the contents of /proc/1/cgroup has changed:

$ cat /proc/1/cgroup
0::/

This is in contrast to pre-commit's checks for _is_in_docker() and _get_container_id:

def _is_in_docker() -> bool:
    try:
        with open('/proc/1/cgroup', 'rb') as f:
            return b'docker' in f.read()
    ...

def _get_container_id() -> str:
    ...
    with open('/proc/1/cgroup', 'rb') as f:
        for line in f.readlines():
            if line.split(b':')[1] == b'cpuset':
                return os.path.basename(line.split(b':')[2]).strip().decode()
    ...

It's not clear yet what has changed with /proc/1/cgroup nor what the fix should be.

Host:

$ rpm -qa |grep docker
docker-ce-cli-27.3.1-1.fc41.x86_64
docker-ce-27.3.1-1.fc41.x86_64
docker-ce-rootless-extras-27.3.1-1.fc41.x86_64
docker-compose-plugin-2.29.7-1.fc41.x86_64
docker-buildx-plugin-0.17.1-1.fc41.x86_64

Guest:

$ rpm -qa |grep docker
docker-compose-plugin-2.29.7-1.fc40.x86_64
docker-buildx-plugin-0.17.1-1.fc40.x86_64
docker-ce-cli-27.3.1-1.fc40.x86_64

pre-commit --version

pre-commit 3.8.0

.pre-commit-config.yaml

repos:
  - repo: local
    hooks:
      - id: shfmt
        name: shfmt
        # shfmt versions can be found here:
        #   https://hub.docker.com/r/mvdan/shfmt/tags
        entry: mvdan/shfmt:v3.8.0
        language: docker_image
        types: [shell]
        args: ["-w"]

~/.cache/pre-commit/pre-commit.log (if present)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions