Lesson 18 of 30
"Run the container as a non-root user" and "run Docker itself without root" sound like the same precaution — they're not, and only one of them protects the host if a container is ever actually broken out of.
11 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
Question 1 of 3
A container runs with `--user 1000:1000` (non-root inside the container), but the Docker daemon itself still runs as root on the host in the normal, default way. If a kernel bug allows a container escape, what's the exposure?
Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
A container is not a VM. It's an ordinary process on the host, made to look isolated by three separate kernel mechanisms working together: namespaces (each container gets its own view of process IDs, network interfaces, mount points, and hostnames — so it can't see the host's other processes or the host's real network, even though it's running on the exact same kernel), cgroups (covered earlier in this track — resource accounting and limits), and capabilities (a finer-grained split of what "root" traditionally means, into dozens of individually grantable/revocable privileges like "bind to a low port" or "load a kernel module"). None of these create a hardware boundary the way a VM's hypervisor does — a container's process is the same kind of kernel-scheduled process as anything else on the host, just with restricted views and restricted permissions layered on top.
That distinction is why two precautions that sound similar are actually solving different problems:
--user 1000:1000 (non-root inside the container) limits what the process running inside the container can do to that container's own filesystem and resources. It doesn't change anything about the Docker daemon or the host.--users# Non-root inside the container — protects the container's own filesystem
docker run --user 1000:1000 myapp:latest
# Rootless Docker — the daemon itself never runs as root on the host at all
dockerd-rootless-setuptool.sh install
docker context use rootless
--user 1000:1000 matters and is genuinely worth doing — a process that's compromised while running as root inside its container can still do a lot of damage within that container's own namespace, and non-root limits that. But it says nothing about the daemon managing that container. Rootless Docker is orthogonal: it's a statement about the daemon's own privilege level, entirely separate from whatever user any individual container's process runs as.
--cap-drop ALL plus only the specific capabilities genuinely needed is a meaningfully tighter default than leaving Docker's defaults as-is."Is running a container as non-root enough to make it secure?" is a genuine trap question — the strong answer distinguishes what non-root-inside-the-container actually protects (the container's own filesystem and processes) from what it doesn't (the daemon's own privilege level, and by extension the host, if an escape ever occurs), and names rootless Docker and capability-dropping as the mechanisms that address the gap. It also connects directly back to the daemon-architecture lesson's core point: daemon privilege is host privilege, so the daemon's own privilege level is a security decision in its own right, separate from anything set on an individual container.