no-docker-socket-mount
Bind-mounting /var/run/docker.sock into a Compose service hands the container root on the host. A filtering socket proxy limits what a service can ask the Docker daemon to do. use_api_socket does not.
On this page
Mounting /var/run/docker.sock into a container is the standard trick for anything that needs to talk to Docker: CI runners, reverse proxies that watch containers, and increasingly AI-agent tooling like MCP gateways that launch tool containers on demand. It is also equivalent to giving that container root on the host, because the Docker API can start privileged containers, mount any host path, and read every volume. This rule flags any service that enables use_api_socket or whose volumes bind-mount the Docker socket, in either the short or long syntax. It resolves ${VAR:-default} interpolation to its default and recognizes the socket under its other host spellings: /run/docker.sock, rootless and Docker Desktop sockets under a home directory, and the Windows named pipe.
What the rule catches
services:
mcp-gateway:
image: docker/mcp-gateway:0.9.0
volumes:
- /var/run/docker.sock:/var/run/docker.sockScanning this file reports:
✖ ERROR [docker-doctor/no-docker-socket-mount]
Service 'mcp-gateway' bind-mounts the Docker socket. Anything running in this container can control the Docker daemon: start privileged containers, read every volume, and escape to the host.Why it matters
The Docker daemon runs as root and its API has no notion of partial trust. Any client can do anything, including docker run --privileged -v /:/host, so a compromised process in a socket-mounted container escapes to the host in one API call. Agent stacks raise the stakes: an MCP gateway or agent runtime executes model-directed actions, so prompt injection anywhere in the toolchain becomes a path to that socket. The MCP gateway advisory CVE-2026-76099 names the Docker API socket as a precondition for host root.
How to fix it
Prefer a read-only filtering socket proxy and reach it over an internal network. The rule treats a proxy as read-only until it finds a common write path, such as POST together with CONTAINERS, EXEC, BUILD, SERVICES, PLUGINS, SWARM, AUTH or SECRETS, a wollomatic -allowPOST, -allowPUT or -allowDELETE, or a port published on every interface. That list is not complete, so turn on only the API sections the service needs. use_api_socket is the same socket plus your registry credentials, so it is not a safer option.
services:
docker-proxy:
image: tecnativa/docker-socket-proxy:0.3.0
environment:
CONTAINERS: 1
INFO: 1
POST: 0
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
networks:
- docker-api
dozzle:
image: amir20/dozzle:v11.4.1
environment:
DOZZLE_REMOTE_HOST: tcp://docker-proxy:2375
ports:
- 127.0.0.1:8080:8080
networks:
- docker-api
- web
networks:
docker-api:
internal: true
web: {}If the service genuinely needs the Docker API, put a filtering socket proxy between it and the daemon:
- Allow only the calls the service needs.
tecnativa/docker-socket-proxyandlinuxserver/socket-proxyturn API sections on with variables, so a client that only reads can getCONTAINERS=1withPOST=0.wollomatic/socket-proxyblocks every call until you allow it with a regular expression per HTTP method. - Know what a section grants.
CONTAINERS=1is not list-only. Through GET calls a client can also read the logs and download the files of every container, andPOST=0does not stop that. - Keep the proxy off the network. Do not publish its port, and reach it from the app over an internal network.
The rule does not report a raw socket mount on those three proxy images when they come from Docker Hub, ghcr.io, or lscr.io and the proxy is read-only, because a proxy has to mount the socket. It still reports a service with build:, and the same image name on any other registry, so a private mirror needs its own ignore entry.
The rule treats a proxy as read-only until it finds a common write path. It then reports the mount again and names the reason. The paths below are the common ones, not a complete list, so a proxy that matches none of them can still be wider than the service needs.
- It can change things. A Tecnativa or linuxserver proxy sets
POST=1together withCONTAINERS=1,EXEC=1,BUILD=1,SERVICES=1,PLUGINS=1,SWARM=1,AUTH=1orSECRETS=1. A client can then start a privileged container, run commands in any container, build images, create a swarm service that bind-mounts the host root, or install a plugin, which is root-equivalent.AUTHandSECRETScount only withPOST, because the Tecnativa README says that withPOSToff every section is read-only,/authaccepts onlyPOST, andGET /secretsreturns no secret data. The linuxserver proxy addsLIBPOD_CONTAINERS=1andALLOW_ARCHIVE=1, which count together withPOST=1. A wollomatic proxy passes any-allowPOST,-allowPUTor-allowDELETEflag, or setsSP_ALLOW_POST,SP_ALLOW_PUTorSP_ALLOW_DELETE, because it allows no such call until you ask for one. An empty pattern allows nothing, so it does not count. The Tecnativa README marksPOSTas security-critical, and the proxy reads a value as an integer, sotruedoes not turn a section on. - It is reachable from the network. The proxy service publishes its own port on all interfaces, in the short or the long syntax. A port bound to
127.0.0.1or::1is fine.
The rule reads environment in map and list form and command. It does not read env_file, so a proxy configured there keeps the exemption. It does not read network_mode: host or the per-container labels of the wollomatic proxy.
use_api_socket: true is not a safer option. Compose mounts the same socket read-write and also copies your registry credentials into the container, so the rule reports it too.
Mounting the socket :ro does not help. Writes go through the connected socket, not the file, so a read-only mount still allows every API call.
Rule details
- Rule key —
docker-doctor/no-docker-socket-mount - Category — Compose
- Default severity —
error - Applies to — Docker Compose files
Explain this rule from the CLI:
npx @docker-doctor/cli@latest rules explain docker-doctor/no-docker-socket-mountChange its severity — or turn it off — in your config file:
// docker-doctor.config.ts
export default {
rules: {
"docker-doctor/no-docker-socket-mount": "off",
},
};Severity affects the health score: error findings cost more points than warning, and info costs the least.