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 mounted into a container (warning for /, /run or /var/run)
What the check looks at
The mounts of every running container, as docker inspect shows them. The check fails for each container that
has /var/run/docker.sock, /run/docker.sock or another docker.sock mounted, read-only or not. It warns when
a container has /, /run or /var/run of the host mounted, since the socket is inside. The agent does not
connect to the socket.
Risk
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".
A :ro mount makes the socket file read-only, and 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
-
Find out why the container has the socket. Typical cases are reverse proxies that read the labels of other containers, dashboards, update tools and CI runners.
-
If the tool can work without it (configuration from a file, a webhook in place 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. -
A tool that has to write (start containers, pull images) has root on the host. Keep it, pin and update its image, and run it only on hosts where that is acceptable.
How to check the fix
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'
The output must be empty.
When a warning is fine
On a host that exists for a tool that needs write access to Docker: a CI runner that starts build containers, a deploy agent, a container update tool. Accept the result on the dashboard with the reason in the note. A mount you did not expect, for example in a monitoring or web container, needs a closer look.
An accepted result stays out of the digest and the counts until it changes.
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 (the sections and
POST=0)