Skip to content

Hardening a container: user, read-only root, capabilities

Select an icon to see what it is.

Step 6 of 6

seccomp filters system calls, --privileged removes it all

Docker applies a default seccomp profile that blocks a list of system calls containers rarely need. /proc/1/status shows Seccomp 2, which means a filter is active. --privileged turns this off and also gives all capabilities and access to host devices, so avoid it.

PrevNext

grep Seccomp /proc/1/status inside the container

default container: Seccomp: 2 (filter active)
docker run --privileged: Seccomp: 0 (no filter), all capabilities, host devices

Try it yourself

Start a hardened container and check each control from inside.

$ docker run -d --name hardened --user 1000:1000 --read-only --tmpfs /tmp --cap-drop ALL --security-opt no-new-privileges alpine sleep 1000
$ docker exec hardened id
$ docker exec hardened touch /x
$ docker exec hardened touch /tmp/x
$ docker exec hardened grep -E 'CapEff|NoNewPrivs|Seccomp' /proc/1/status
$ docker rm -f hardened

Quiz

1. Why run the process with --user 1000:1000?
2. What does --read-only do?
3. Which flag removes all Linux capabilities?