Skip to content

Docker audit fix · Volume Permissions

How to Enforce Read-Only Volume Mounts in Docker

Docker gives every container a writable root filesystem unless it is started with --read-only, letting a compromised process drop binaries anywhere in the image. Set --read-only, then add tmpfs or named volumes for the paths that must be written.

Hiren KalariyaHiren KalariyaLast reviewed readonly-volume-enforcement
CtrlOpsRead-Only Volume EnforcementMEDIUM

What did your audit say?

WARN · when the audit printed

Some are not

At least one container can write to its own root filesystem, so a process that gets code execution there can drop or modify files. The message names up to five and gives the full count.

Severity
Medium
Needs root or sudo
Yes
Results it can return
WARN · SKIP · PASS
Check in this audit
7 of 7

Every threshold on this page is transcribed from the docker-security-volume-permissions audit script that CtrlOps runs, and a build check fails if the two ever disagree. See all 7 Volume Permissions checks, or how the audit runs.

For every container docker ps -a returns, running or stopped, the check reads one inspect field: .HostConfig.ReadonlyRootfs. It counts the containers where that boolean is anything other than true, which is the value --read-only or Compose read_only: true sets. Every container reading true is the PASS; one that does not is enough for a WARN, and the message quotes up to five names alongside a complete N of M count. With no containers at all there is nothing to read and the check SKIPs.

Needs the docker binary and daemon access; otherwise SKIP. It iterates docker ps -a - all containers, running or stopped - and reads one field, .HostConfig.ReadonlyRootfs. Despite the name, it does not examine volume mounts at all: it is the same root-filesystem test as the Read-Only Filesystem check in the Container Hardening script, differing only in that it covers stopped containers too and is rated MEDIUM rather than LOW. Expect the two to report together. With no containers at all it SKIPs.

What each result means
ResultWhenWhat it means
SKIPDocker not installed, daemon unreachable, or no containers at allNothing was verified. No container was inspected, so this is an absence of input rather than a clean result.
PASSAll containers are --read-onlyEvery container on the host, stopped ones included, starts with a read-only root filesystem. Mounted volumes are not assessed and can still be writable.
WARNSome are notAt least one container can write to its own root filesystem, so a process that gets code execution there can drop or modify files. The message names up to five and gives the full count.

Identical principle to the Read-Only Filesystem check (CIS Docker 5.12, OWASP Rule #8). Differences: this one is MEDIUM and covers stopped containers as well.

  • Near-duplicate of read-only-filesystem; a single fix clears both. Expect both to WARN on unhardened stacks.
  • Stopped containers that will never run again still count; prune them.
  • Converting a container to --read-only is iterative: start it, watch the logs for "Read-only file system" errors, add --tmpfs for scratch paths (/tmp, /run, /var/cache) and named volumes for data, then repeat.
  1. Find out what the container writes

    Run this against a working copy started without --read-only. Every A or C line is a path that needs a writable mount.

    sh
    docker diff <name>

  2. Turn on --read-only with writable mounts for those paths

    sh
    docker run --read-only --tmpfs /tmp --tmpfs /run -v data:/var/lib/app ...

    In Compose:

    yaml
    read_only: truetmpfs:  - /tmp  - /run

    Use a tmpfs for scratch space that can vanish on restart, and a named volume for anything the app must keep.

  3. Recreate and watch the logs

    sh
    docker compose up -d --force-recreatedocker logs <name> 2>&1 | grep -iE 'read-only file system|EROFS'

    Each hit is a path you missed. Add a tmpfs or volume for it and recreate again until the logs are clean.

  4. Remove stopped containers you no longer need

    Unlike the Read-Only Filesystem check, this one counts stopped containers too. Delete the obsolete ones rather than converting them.

    sh
    docker ps -a --filter status=exiteddocker rm <name>     # or: docker container prune

sh
docker inspect -f '{{.Name}} readonly={{.HostConfig.ReadonlyRootfs}}' $(docker ps -aq)# expected: true for every container# Prove enforcement, and that scratch space still works:docker exec <name> sh -c 'touch /probe' 2>&1          # expected: Read-only file systemdocker exec <name> sh -c 'touch /tmp/probe && echo tmpfs ok'# Find out what a container writes, so you know which paths need a mount:docker diff <name> | head -20

Debugging

  • Either nothing exists on this host, or the audit ran with root while the daemon was stopped, so the container list came back empty. Run sudo docker ps -a: if it errors, start Docker (sudo systemctl start docker) and re-run the audit. The Docker Inventory check tells the two cases apart.
  • A plain docker ps failed for the audit account and there was no root or sudo to retry with, or command -v docker found nothing on its PATH. Run the audit as root, with sudo, or as a member of the docker group.
  • Expected: both read ReadonlyRootfs. Fixing it clears both. This one also counts stopped containers, so the totals can differ.
  • It needs writable paths. docker diff on a running copy without the flag lists every added or changed path; supply those as --tmpfs (ephemeral) or named volumes (persistent). /tmp and /run are almost always required.
  • HostConfig changes need the container recreated: docker compose up -d --force-recreate. Verify with docker inspect, which is what the check reads.
  • Despite the check's name, mounts are not assessed. Use the Writable Volume Mounts check and add :ro to any mount that does not need write access.
  • The message truncates at 5; the N of M count is complete.

Sources

Next

Re-run the Volume Permissions audit after applying the fix and confirm this check moves to PASS. CtrlOps runs all 7 checks over your existing SSH connection and scores the result, so the change is visible without reading another config file.

Download for MacDownload for WindowsAll 7 Volume Permissions fixes

14-day free trial, no credit card required.

Explore article with AI tools

Written by

Hiren Kalariya

Co-Founder & CEO, TST Technology

Hiren Kalariya is the Co-Founder and CEO of TST Technology and the product lead behind CtrlOps, a local-first desktop app that makes Linux server management fast and easy for developers and DevOps teams. Over the past five years he has shipped 60+ production systems, and he still tests every tool he writes about on real servers.

Stop juggling tools. Start managing fleets.

PuTTY
Termius
MobaXterm
WinSCP
SecureCRT
Royal TS
Warp
CtrlOps14 tools left
Webmin
aaPanel
RunCloud
Dokploy
IP spreadsheet
bash (2)
sticky notes

One app. All your servers. No context switching. Free to start, free to leave.

Start instantly · No credit card · Cancel anytime

Your privacy preferences. We use product analytics to improve CtrlOps. Google Analytics cookies and live chat stay off until you allow them. Cookie policy