Lesson 7 of 9 · 20m
Rootless Docker: Containers Without Root
User namespaces let the whole Docker stack run as a regular user — closing the 'container breakout = root on host' equation for good.
The uncomfortable fact about default Docker: the daemon runs as root, and being able to talk to the docker socket is root on the host. docker run -v /:/host ubuntu chroot /host — done. Rootless mode restructures the whole thing: the daemon runs as your user, inside a user namespace, and even a full container breakout lands in a process that owns nothing.
User namespaces: the trick that makes it work
The kernel's user namespace remaps UIDs. Inside the namespace you're UID 0 (root); outside — on the host — you're some high unprivileged UID like 100999:
inside container: root (uid 0)
host reality: uid 100999 — owns nothing, can read nothing privateA process that breaks out of a rootless container finds itself as a nobody user with no capabilities. Compare with rootful Docker, where breakout-as-root is host root immediately. This is the single largest security upgrade available for single-node Docker, and it costs an afternoon.
Setting it up
# modern docker ships the tooling
dockerd-rootless-setuptool.sh install
systemctl --user enable --now docker
export DOCKER_HOST=unix:///run/user/1000/docker.sock
docker run --rm alpine id # uid=0(root) — inside. outside it's nobody.What changes under the hood: containerd and dockerd run as you, images live in ~/.local/share/docker, and the network stack can't create real bridges — instead it uses slirp4netns, a user-space TCP/IP stack. That last part is where the caveats live.
The honest limitations
- Networking is NAT-through-userspace: no real host networking, worse throughput (fine for dev, measure for prod), and the source IP of container traffic is rewritten.
- No privileged ports the normal way — binding below 1024 requires sysctl
net.ipv4.ip_unprivileged_port_startadjustment or a reverse proxy. - cgroups v2 is required for resource limits, and on some distros user delegation must be configured (
systemctl edit user@/ cgroup controllers). - Some workloads can't cope: anything needing real NET_ADMIN, mount tricks, or direct hardware. Kubernetes-in-Docker (kind) works but nested virtualization cases get weird.
When rootless is the right answer
Developer laptops, CI runners executing untrusted builds, shared jump boxes, build machines. Anywhere you'd flinch at handing out docker group membership — and you should flinch, because the docker group is passwordless sudo that nobody audits.
Field notes
docker infoshowsrootlessunder Security Options — check before assuming.- Rootless per-user daemons mean per-user image storage — no sharing layers between users on the same host. Disk cost is the trade.
- For production single-host deployments, rootless + a reverse proxy is a defensible posture. For multi-node, the conversation moves to Kubernetes pod security standards instead.
- The socket still matters: rootless or not, anyone who can write to the docker socket controls that daemon's containers. Scope it accordingly.
Was this lesson helpful?