brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: mounting the Docker socket read-only does not make it safe

Docker
~/tips/tip-docker-socket-readonly-not-safe

- /var/run/docker.sock:/var/run/docker.sock:ro

Know that :ro on docker.sock still lets a container control Docker fully.

Dashboards, update checkers and reverse proxies often ask for /var/run/docker.sock, and guides add :ro to feel better about it. That suffix does not do what it suggests.

volumes:
  - /var/run/docker.sock:/var/run/docker.sock:ro

:ro makes the socket file read-only in the mount, which stops the container from deleting or replacing the file. Talking to a Unix socket is not a write to the file, though. The container can still send any API request through it: create a container, mount the host’s root filesystem, start it. The Docker security docs warn that only trusted users should be allowed to control the daemon.

What does limit it is a socket proxy, a small container that sits between the app and the real socket and only forwards the API calls you allow. A typical setup for a dashboard allows listing containers and nothing else. The app then gets the proxy’s address instead of the socket:

environment:
  DOCKER_HOST: tcp://socket-proxy:2375

I would keep that proxy on an internal network shared only with the app, never published on a port. And it is worth asking whether a tool needs the socket at all; plenty of monitoring can be done from the host instead.

A proxy that allows POST requests or container creation gives most of the power back. Check its settings, not just that it is there.

Further reading: Docker Engine security, Protect the Docker daemon socket

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link