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
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/commwassystemd; - it could read their command lines, the same as
ps -efshows; tokens or passwords given as arguments are visible; kill -0 1succeeded 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/environwas denied, because the container lacksCAP_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.
- Check why the container has it. Monitoring agents that report on host processes and some debugging tools need it; applications and databases do not.
- Remove
pid: hostfrom the compose file, or--pid=hostfrom thedocker runcommand. - 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
- Docker docs: docker container run, --pid
- Docker docs: Isolate containers with a user namespace — host PID namespace is incompatible with user namespace remapping.
- proc(5) — access to
/proc/[pid]/environneeds ptrace access mode checks.