DevOpsInterview.Cloud
Docker

Docker Socket Exposed - Why That's Dangerous

2 min read

A container that gets /var/run/docker.sock mounted into it effectively holds the keys to the host. This question shows up constantly in DevOps and security-leaning interviews because it is a mistake that looks harmless in a Dockerfile or CI config but hands out root.

The answer interviewers want

The Docker socket equals root access to the host. It is not a scoped API endpoint, it is a direct line to the Docker daemon, and the daemon runs as root. If a container has that socket mounted, anything running inside it can talk to the daemon as if it were the host's root user.

Concretely, a container with access to the socket can:

  • Start new containers, including privileged ones
  • Mount the host filesystem into those new containers
  • From there, read or write anything on the host

Once an attacker can spin up a privileged container and bind-mount /, it's game over. They have full host access, not just container access.

The fix is to avoid mounting the socket at all. Options that come up in practice:

  • Use the Docker API over TLS instead of mounting the raw socket, so access is authenticated and encrypted rather than a bare filesystem handle
  • Use Docker-in-Docker (dind) where the nested daemon is isolated from the host daemon
  • Use CI runners built with proper isolation (ephemeral VMs, gVisor, Kata Containers, or similar) so a compromised build job can't reach the host daemon at all

One detail worth stating explicitly: mounting the socket read-only does not fix the problem. Even with a read-only mount, an attacker can still query the Docker API to inspect running containers, pull environment variables, secrets, and network configuration. Read-only only restricts filesystem writes to that one file, it does nothing to limit what the API itself exposes. The practical rule is simple: never mount that socket into a container you don't fully trust.

Why interviewers ask this

This question separates people who've only used Docker from people who understand what the daemon actually is: a root-privileged process with a powerful API. Interviewers want to see that you recognize the socket as a privilege boundary, not just a path, and that you have a real alternative ready instead of just saying "don't do that."

Follow-ups to expect

"Is a read-only socket mount safe?" No. Read-only still exposes the full Docker API for inspection, which is enough to leak secrets and network configuration even without write access.

"How would you set up CI to build Docker images without this risk?" Use CI runners with real isolation, ephemeral and sandboxed, so a compromised build can't reach the host daemon, or use Docker-in-Docker with its own isolated daemon.

"What's the actual attack path once someone has the socket?" They start a new container, request it as privileged, mount the host filesystem into it, and now have host-level read/write access.

The common wrong answer

Most candidates say mounting the socket is "a bad practice" without explaining why, or they think marking the mount read-only solves the problem. Neither answer shows they understand that the socket is a root-equivalent API, not just a sensitive file.

Prefer it spoken? Watch the 30-second answer on YouTube

More Docker questions