Checks / Docker and containers

A container shares the host PID namespace

Check
docker.host_pid
Severity
medium
Runs
on the server, in the daily run of the agent
Looks at
PidMode is host
Updated 26 Nov 2026

What the check looks at

The agent reads HostConfig.PidMode of every running container from docker inspect and reports each container where it is host. The setting comes from --pid=host on docker run or pid: host in a compose file.

Why it matters

Each container normally has its own process namespace: its first process is PID 1 and it cannot see anything else. With --pid=host the container shares the process list of the host. In a test on Docker 29.9:

  • the container saw all processes of the host, and /proc/1/comm was systemd;
  • it could read their command lines, the same as ps -ef shows; tokens or passwords given as arguments are visible;
  • kill -0 1 succeeded from a root process in the container on a host without an AppArmor profile for containers, so the container could send signals to host processes, including stopping them;
  • reading /proc/1/environ was denied, because the container lacks CAP_SYS_PTRACE.

SYS_PTRACE or --privileged removes that limit: capabilities(7) describes CAP_SYS_PTRACE as the right to "trace arbitrary processes using ptrace(2)".

How to fix it

The commands are the same on every distribution.

  1. Check why the container has it. Monitoring agents that report on host processes and some debugging tools need it; applications and databases do not.
  2. Remove pid: host from the compose file, or --pid=host from the docker run command.
  3. Recreate the container: docker compose up -d --force-recreate <service>.

If two containers need to see the processes of one another (a sidecar that debugs an application), share the namespace of that one container with --pid=container:<name> instead of the one of the host.

How to check the fix

docker ps -q | xargs -r docker inspect --format '{{.Name}} pid={{.HostConfig.PidMode}}' | grep 'pid=host'

No output means no running container shares the host PID namespace.

When a warning is fine

A monitoring agent that reports per-process figures of the host needs it, and so does a container you start for a debugging session. If its image comes from a source you trust and runs without extra capabilities, accept the result for that container on the dashboard. Do not combine it with --privileged or SYS_PTRACE unless the tool needs that too.

An accepted result is left out of the digest and the counts until it changes; then it shows again.

Sources