Containers · Term

What is the Docker socket?

The Docker socket is the control channel for the Docker daemon. If it is mounted into a container, that container has full root control of the host. Here is why /var/run/docker.sock is so dangerous to expose.

Containers · TermCloud Penetration Testing
TL;DR

The Docker socket (/var/run/docker.sock) is the API endpoint for the Docker daemon, which runs as root on the host. Anything that can talk to it can create containers, mount the host filesystem, and run code as root on the host. Mounting the socket into a container (a common convenience for CI and monitoring tools) therefore hands that container full control of the host, making escape trivial. Treat socket access as root-equivalent.

By John Dill, Red Team Lead, SecureLayer7Updated

What the Docker socket is

The Docker daemon (dockerd) does the real work of running containers, and it listens on a Unix socket at /var/run/docker.sock. The docker CLI is just a client that sends API requests to that socket.

The daemon runs as root, and the socket has no fine-grained permissions: if you can talk to it, you can ask the daemon to do anything, including starting a new container that mounts the whole host.

The abuse and payload

If a container has the socket mounted (-v /var/run/docker.sock:/var/run/docker.sock), an attacker inside uses it to own the host:

- Install the docker client or use the API directly, then launch a container that mounts host root: docker -H unix:///var/run/docker.sock run -v /:/host -it alpine chroot /host sh - That gives a root shell on the host filesystem, escaping the original container entirely.

The same is true for an exposed TCP Docker API (port 2375 without TLS). Documented techniques shown for defenders.

How to defend

  • Do not mount the Docker socket into application containers. Find another way to do what the tool needs.
  • Never expose the Docker API over TCP without mutual TLS; avoid 2375 entirely.
  • Use rootless Docker or a socket proxy that allows only the minimal API calls a tool requires.
  • In Kubernetes, prefer the standard APIs over mounting host sockets; block hostPath mounts of sockets.
  • Scan for socket mounts in compose files and manifests.

References

  1. [1]Docker docs: Daemon remote access(Docker)
  2. [2]NIST SP 800-190 Application Container Security Guide(NIST)
  3. [3]MITRE ATT&CK: Containers Matrix(MITRE)
Related terms

Common questions

Container security, asked often

Want your containers and clusters tested for these paths?

Scope an engagement

Find the container escape paths before an attacker does.

We test your Docker hosts and Kubernetes clusters the way a real intruder would, from a compromised pod to the node and the rest of the cluster, then hand your team reproducible evidence and a fix for every step. Free re-test included.

See cloud penetration testing30-min scoping call, fixed-price proposal in 48 hours.