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.
| Result | When | What it means |
|---|---|---|
| SKIP | Docker not installed, daemon unreachable, or no containers at all | Nothing was verified. No container was inspected, so this is an absence of input rather than a clean result. |
| PASS | All containers are --read-only | Every container on the host, stopped ones included, starts with a read-only root filesystem. Mounted volumes are not assessed and can still be writable. |
| WARN | 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. |
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-onlyis iterative: start it, watch the logs for "Read-only file system" errors, add--tmpfsfor scratch paths (/tmp,/run,/var/cache) and named volumes for data, then repeat.
Find out what the container writes
Run this against a working copy started without
--read-only. EveryAorCline is a path that needs a writable mount.sh docker diff <name>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 - /runUse a tmpfs for scratch space that can vanish on restart, and a named volume for anything the app must keep.
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.
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
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- 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 psfailed for the audit account and there was no root or sudo to retry with, orcommand -v dockerfound nothing on itsPATH. Run the audit as root, with sudo, or as a member of thedockergroup. - Expected: both read
ReadonlyRootfs. Fixing it clears both. This one also counts stopped containers, so the totals can differ. - It needs writable paths.
docker diffon a running copy without the flag lists every added or changed path; supply those as--tmpfs(ephemeral) or named volumes (persistent)./tmpand/runare almost always required. HostConfigchanges need the container recreated:docker compose up -d --force-recreate. Verify withdocker inspect, which is what the check reads.- Despite the check's name, mounts are not assessed. Use the Writable Volume Mounts check and add
:roto any mount that does not need write access. - The message truncates at 5; the
N of Mcount is complete.
