Containers give you isolation, not virtualization. Confuse the two and a web-container command injection becomes full host root.
Containers do not provide virtualization. They provide isolation. Treat isolation as a hard security boundary and a low-privilege injection inside a web container can become root on the host.
One of the most battle-tested tools for finding these misconfigs is dockerscan by cr0hn:
https://github.com/cr0hn/dockerscan
Three misconfigurations cause most container breaches.
1. The exposed Docker socket
Teams mount the host socket into a container as a Docker-in-Docker shortcut:
# catastrophic: volumes: - /var/run/docker.sock:/var/run/docker.sock Write access to the socket is root on the host — no kernel exploit needed:
docker run -v /:/host -it alpine chroot /host That mounts the entire host filesystem and drops you into a root shell.
2. Privileged containers
The --privileged flag strips almost all isolation: AppArmor/SELinux off, all of /dev exposed, dangerous capabilities (CAP_SYS_ADMIN, CAP_SYS_MODULE) granted. From there an attacker can mount disks, load kernel modules, or escape via the cgroup-v1 release_agent trick.
3. Image-layer secret leakage
Deleting a secret in a later step does not remove it from the image:
RUN export AWS_SECRET_KEY="AKIA..." && ./build.sh RUN rm -rf /secrets.env # only writes a whiteout layer Image layers are immutable. Tools like dockerscan read every historical layer and pull out tokens, SSH keys and passwords in seconds.
The hardened checklist
- Never mount the Docker socket. Use rootless builds, Kaniko, or isolated runner VMs.
- Drop all capabilities (
--cap-drop=ALL) and add back only what the binary needs (CAP_NET_BIND_SERVICE). - Run as non-root —
USER appuser, never UID 0. - Keep secrets out of layers with multi-stage builds or BuildKit
--mount=type=secret.
When did you last audit your production images and daemon config? Comment below.