Skip to content

Namespaces: what a container can see

Select an icon to see what it is.

Step 6 of 6

Sharing a host namespace

With --pid=host or --network=host, docker leaves that namespace out of the OCI config, so runc does not create it. The container then sees the host's processes or network directly. This removes isolation, so use it only when you need it.

$ docker run --rm --pid=host alpine ps
PrevNext

docker run --pid=host

pid namespace: not created, uses the host's
ps inside the container lists host processes

Try it yourself

Compare a container's namespaces with the host's.

$ docker run -d --name web nginx
$ PID=$(docker inspect --format '{{.State.Pid}}' web)
$ sudo ls -l /proc/$PID/ns
$ sudo ls -l /proc/1/ns
$ grep NSpid /proc/$PID/status
$ docker run --rm --pid=host alpine ps
$ docker rm -f web

Quiz

1. How can you tell two processes share a namespace?
2. Why is nginx PID 1 inside the container but a larger PID on the host?
3. What does --network=host do?