Skip to content

Docker audit fix · Volume Permissions

How to Secure Docker Writable Volume Mounts on Linux

Docker mounts every volume read-write unless you append :ro, and a read-write docker.sock is root on the host for anyone inside that container. Count the writable mounts, then make :ro the default for anything a container only reads.

Hiren KalariyaHiren KalariyaLast reviewed volume-rw-access
CtrlOpsWritable Volume MountsHIGH

What did your audit say?

FAIL · when the audit printed

docker.sock mounted read-write

A container has the Docker daemon socket mounted read-write, which is equivalent to root on the host. The message names each container.

Severity
High
Needs root or sudo
Yes
Results it can return
FAIL · SKIP · PASS
Check in this audit
2 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, the check inspects each entry in .Mounts - bind mounts, named volumes and tmpfs alike - and reads its Source and its RW flag. A mount with RW set to true increments the read-write counter and anything else increments the read-only counter, and both numbers end up in the message. The only condition that produces a finding is a read-write mount whose source is /var/run/docker.sock or /run/docker.sock, which FAILs and names each container. Every other combination is a PASS, including a host where all mounts are writable, so the counts carry more information than the status does.

Needs the docker binary and daemon access; otherwise SKIP. It iterates all containers (docker ps -a) and every mount type - bind mounts, named volumes and tmpfs alike - counting how many are read-write versus read-only. Only one condition produces a finding: the docker socket mounted read-write. Everything else is reported as a PASS carrying the counts, so a host where every mount is writable still passes with an advisory message. Read the counts, not just the status. Note that a read-only docker.sock mount is not a FAIL here - it is still a full host compromise, and is caught by the Docker Socket In Containers check instead.

What each result means
ResultWhenWhat it means
SKIPDocker not installed, or daemon unreachableNothing was verified. No mount was counted, so a read-write docker.sock could be present and unreported.
FAILdocker.sock mounted read-writeA container has the Docker daemon socket mounted read-write, which is equivalent to root on the host. The message names each container.
PASSNo mounts at allNo container on this host mounts anything, so there is no writable host path to review.
PASSCounts of RW and RO mounts (informational)The socket is not mounted read-write, but this is an inventory rather than an all-clear: read the read-write count and add :ro wherever a container does not need to write.

Same root cause as Docker Socket In Containers (daemon-socket script). This check adds the RW/RO inventory as a nudge toward read-only mounts (CIS Docker 5.12 spirit, OWASP Rule #8).

  • A read-only socket mount (:ro) does not prevent API calls (the client connects to the socket; it does not write the inode), so a PASS here with a :ro socket is still dangerous; the Docker Socket In Containers check catches both on running containers.
  • /etc/hosts and /etc/resolv.conf, which Docker mounts into every container, are not in .Mounts and are not counted. The anonymous volumes Docker creates for an image's VOLUME directives are, and they are read-write.
  1. List every mount and its RW flag

    sh
    docker inspect -f '{{.Name}}{{range .Mounts}} {{.Source}}->{{.Destination}}(rw={{.RW}}){{end}}' $(docker ps -aq)

  2. Remove the docker.sock mount

    Delete the docker.sock line from the service and recreate it. If a tool genuinely needs the Docker API, put a filtering socket proxy in front of it, as the Docker Socket In Containers fix shows. Changing the mount to :ro clears this check's FAIL but leaves the container in control of the host.

  3. Add :ro to mounts the container only reads

    Config, certificates and static files rarely need write access.

    sh
    docker run -v /srv/app/config:/etc/app:ro ...docker run --mount type=bind,src=/srv/app/config,dst=/etc/app,readonly ...

    In Compose:

    yaml
    services:  app:    volumes:      - ./config:/etc/app:ro      - type: volume        source: static        target: /usr/share/nginx/html        read_only: true

  4. Recreate the containers

    Mount options are fixed when a container is created.

    sh
    docker compose up -d --force-recreate

sh
# Every mount with its RW flag:docker inspect -f '{{.Name}}{{range .Mounts}} {{.Source}}->{{.Destination}}(rw={{.RW}}){{end}}' $(docker ps -aq)# expected: no docker.sock at all, and rw=false wherever the container does not need to write# Count them the way the check does:docker inspect -f '{{range .Mounts}}{{.RW}}{{println}}{{end}}' $(docker ps -aq) | sort | uniq -c# Prove a read-only mount is enforced:docker exec <name> sh -c 'touch /data/probe' 2>&1     # expected: Read-only file system

Debugging

  • The check printed one of two messages. "Docker not installed" means command -v docker found nothing on the audit account's PATH. "Cannot query Docker daemon" means a plain docker ps failed for the audit account and there was no root or sudo to retry with: run the audit as root, with sudo, or as a member of the docker group. The Docker Inventory check reports whether the daemon itself is reachable.
  • With root or sudo available, a stopped daemon does not produce a SKIP. The check goes on to as_root docker ps -a, which fails quietly and returns no containers, so there are no mounts to count and the result is this PASS. On a host where Docker may be down, run sudo docker ps -a before trusting it.
  • The check's normal output, not a clean bill of health. Every writable mount is a path a compromised container can modify on the host. Go through the list and append :ro wherever write access is not needed.
  • The most serious finding in this script: that container can create a privileged container and own the host. Remove the mount, or route the tool through a socket proxy exposing only the endpoints it needs. Changing it to :ro downgrades this check but does not fix the problem - see the Docker Socket In Containers check.
  • Mount options are fixed at creation; recreate it (docker compose up -d --force-recreate) and confirm with docker inspect. Note also that :ro on a named volume still allows another container with a writable mount of the same volume to change the data.
  • Every mount of every container is counted, including tmpfs and containers that are stopped. Use the first command to see exactly what is being counted.

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