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: add :ro to a Docker bind mount when the container only needs to read

Docker
~/tips/tip-docker-bind-mount-read-only

docker run -d --name web \

Mount config folders read-only so a container can read but never change them.

Most containers only need to read their config, certificates or media library. A read-only mount makes sure a bug, a bad update or a compromised app cannot change the files on your host.

docker run -d --name web \
  -v "$PWD/conf:/etc/nginx/conf.d:ro" \
  -v /srv/media:/media:ro \
  nginx:alpine

Inside the container, any write to those paths fails with Read-only file system. In Compose the same suffix works in the short syntax, ./conf:/etc/nginx/conf.d:ro, and with --mount you add readonly to the list of options.

I’d start every mount as read-only and remove :ro only where the app complains. A media server that should never delete your films is the best example, and certificates and config folders are close behind.

Some apps write to a folder you would expect to be read-only: they rewrite their own config at startup, or create a lock file next to it. They will crash or log errors with :ro. In that case mount the config file read-only and give the app a separate writable folder for its state, or drop the flag for that one mount.

Further reading: Bind mounts

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