Checks / Docker and containers
A container has the Docker socket
- Check
docker.socket_mount- Severity
- high
- Runs
- on the server, in the daily run of the agent
- Looks at
- /var/run/docker.sock or /run/docker.sock is mounted into a container
What the check looks at
The agent reads the mounts of every running container, as docker inspect shows them, and reports each
container where /var/run/docker.sock or /run/docker.sock is mounted. It reports the container name and
the mount, read-only or not. It does not connect to the socket.
Why it matters
The socket is the API of the Docker daemon, which runs as root. A process that can send requests to it can start a new container with the root directory of the host mounted and change any file there. The Docker documentation says that "only trusted users should be allowed to control your Docker daemon".
Mounting the socket with :ro does not change this. It makes the socket file read-only, but requests still
go through: in a test on Docker 29.9, a container with a :ro mount received OK from the /_ping
endpoint. A bug in the container, or a malicious version of its image, gives an attacker root on the host.
How to fix it
The commands are the same on every distribution.
-
Find out why the container has the socket. Typical cases are reverse proxies that read labels of other containers, dashboards, update tools and CI runners.
-
If the tool can work without it (configuration from a file, a webhook instead of polling), remove the volume from the compose file or the
docker runcommand and recreate the container:docker compose up -d --force-recreate <service> -
If the tool only reads (lists containers, reads labels, follows events), put a filtering proxy in front of the socket, such as docker-socket-proxy with
POST=0, and point the tool at the proxy over an internal Docker network. The tool then gets the read endpoints it needs and a 403 for everything else. -
If the tool has to write (start containers, pull images), it has root on the host by its nature. Keep it, pin and update its image, and limit it to hosts where that is acceptable.
How to check the fix
List the running containers that still have the socket:
docker ps -q | xargs -r docker inspect --format \
'{{.Name}}{{range .Mounts}}{{if eq .Destination "/var/run/docker.sock" "/run/docker.sock"}} has the socket{{end}}{{end}}' \
| grep 'has the socket'
No output means none. The next report of the agent shows the check as passed.
When a warning is fine
Some tools cannot work without write access to Docker: a CI runner that starts build containers, a deploy agent, a container update tool. On a host that exists for that tool, the finding describes a decision you took. Accept the result on the dashboard and write the reason in the note. A mount you did not expect, for example in a monitoring or web container, deserves a closer look.
An accepted result is left out of the digest and the counts until it changes; then it shows again.
Sources
- Docker docs: Docker security, Docker daemon attack surface
- Docker docs: Linux post-installation steps — access to the daemon grants root-level privileges.
- Tecnativa docker-socket-proxy README — sections
and
POST=0.