For every container docker ps -a returns, running or not, the check inspects .Mounts, keeps only the entries whose Type is bind, and tests each one's source path against a single fixed regular expression. That pattern matches / exactly, and /etc, /root, /boot, /proc, /sys, /dev, /var/lib/docker or /home either on their own or with a trailing subpath, plus the daemon socket at /var/run/docker.sock or /run/docker.sock. One matching source anywhere on the host is enough to fail the check, and every hit is reported as container:src->dst; no match on any container is the PASS. The mount's read-only flag is never read, so a :ro bind of /etc still counts as a hit.
Needs the docker binary and daemon access; otherwise SKIP. Unlike the Container Hardening checks, this one iterates docker ps -a - every container, running or not - so a stopped container with a dangerous mount is still reported. It examines only Type == "bind" mounts, so a named volume that happens to hold sensitive data is not matched. The source path is tested against a fixed list: / exactly, /etc, /root, /boot, /proc, /sys, /dev, /var/lib/docker, /home, and the docker socket under either /var/run or /run. Sensitive paths outside that list (/srv, /opt/secrets, /var/lib/mysql) are not flagged, and the mount's read-only flag is deliberately ignored - read access to /etc or /root is itself the finding.
| Result | When | What it means |
|---|---|---|
| SKIP | Docker missing / daemon unreachable | Nothing was verified. No container was inspected, so a dangerous bind mount could be present and unseen. |
| FAIL | Any sensitive source mounted | At least one container has a bind mount of a host path that hands over the host, and the message names the container, source and destination for each hit. |
| PASS | None | No container binds any path on the fixed sensitive list. Sources outside that list, and named volumes of any kind, were never assessed. |
A bind mount is a hole in the container boundary. / or /etc lets a compromised container rewrite passwd, sudoers, cron, or SSH keys; /dev exposes block devices; /proc and /sys expose kernel tunables and /proc/sysrq-trigger; /var/lib/docker exposes every other container's layers and volumes; /home exposes user files and SSH keys. CIS Docker 5.5 "Ensure sensitive host system directories are not mounted on containers"; OWASP Docker Cheat Sheet Rule #1 and Rule #8; NIST SP 800-190 4.4.4.
- Developer bind mounts under
/home/<user>/projectare extremely common and match^/home($|/). On a production VPS that is usually a deployment smell (code should be baked into the image or live in/srv//opt), but for dev hosts it is a loud false positive. On a server, moving the project to/srvor/opt, or building it into the image, clears it; on a dev host, record it as an exception. - Monitoring agents (node-exporter, cAdvisor, Datadog, Netdata) mount
/proc,/sys,/read-only by design. Read-only reduces but does not remove risk (/procstill leaks host process info). Keep them:ro, drop capabilities, and document. - Certificate mounts like
/etc/letsencrypt:/certs:roand/etc/localtime:/etc/localtime:romatch/etc, and so does every path beneath it. Narrowing the bind to one file under/etcreduces the risk but does not clear the finding; copying the file to a path outside the list does./etc/localtimeis harmless but still reported. - Named volumes (
Type == volume) are never flagged. - Stopped containers count; remove stale ones (
docker container prune) to clear findings.
List every bind mount
Stopped containers count too, so list them all.
sh docker inspect -f '{{.Name}}{{range .Mounts}}{{if eq .Type "bind"}} {{.Source}}->{{.Destination}}{{end}}{{end}}' $(docker ps -aq)Move data and code off the host paths
Data belongs in a named volume, which this check never flags; code belongs in the image. A project that has to stay on the host lives under
/srvor/opt, not/home.yaml services: app: volumes: - appdata:/var/lib/appvolumes: appdata:Copy the files a container needs out of the listed paths
The pattern matches every path under
/etc, so a bind of/etc/ssl/certs/ca.pemis still reported. Copy the file to a directory outside the list and bind that instead. For Let's Encrypt certificates, a certbot deploy hook keeps the copy current on every renewal:sh sudo install -d -m 750 /srv/app/certssudo tee /etc/letsencrypt/renewal-hooks/deploy/copy-to-app.sh >/dev/null <<'EOF'#!/bin/shcp -L "$RENEWED_LINEAGE/fullchain.pem" "$RENEWED_LINEAGE/privkey.pem" /srv/app/certs/EOFsudo chmod +x /etc/letsencrypt/renewal-hooks/deploy/copy-to-app.shRun the
cponce by hand for the first copy. For the time zone, setTZ=Europe/Berlin(or your zone) in the container's environment instead of mounting/etc/localtime.Keep only documented read-only exceptions
A monitoring agent or a socket proxy may genuinely need one of these paths. Mount it read-only and as narrowly as the tool allows (
/procrather than/), run it non-root with--cap-drop ALL, and record the exception: the check has no allow-list and ignores the read-only flag, so the finding stays.Recreate and clean up
Mounts are fixed when a container is created, and a stopped container still counts.
sh docker compose up -d --force-recreatedocker rm <old-container> # or: docker container prune
# Every bind mount on every container, with its read-only flag:docker inspect -f '{{.Name}}{{range .Mounts}}{{if eq .Type "bind"}} {{.Source}}->{{.Destination}}(rw={{.RW}}){{end}}{{end}}' $(docker ps -aq)# expected: no source under /, /etc, /root, /boot, /proc, /sys, /dev, /var/lib/docker, /home, or docker.sock# Check the definitions too, so the finding does not come back on the next deploy:grep -rn -E 'volumes:|/etc|/root|docker.sock' docker-compose.yml compose.yaml 2>/dev/null# Confirm what a container can actually reach:docker exec <name> ls -la /host-etc 2>/dev/null- The check printed one of two messages. "Docker not installed" means
command -v dockerfound nothing on the audit account'sPATH. "Cannot query Docker daemon" means a plaindocker psfailed 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 thedockergroup. 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, and an empty list has no sensitive mounts in it, so the result is PASS. On a host where Docker may be down, runsudo docker ps -abefore trusting that PASS. - Expected, and worth fixing rather than ignoring: the mount takes effect the moment someone starts it.
docker rmit if it is obsolete. - cAdvisor, node-exporter, Datadog and similar genuinely mount
/proc,/sysand sometimes/. Mount them read-only, scope them as narrowly as the agent allows (/procrather than/), keep the container non-root, and record the exception. The check has no allow-list, so the finding will persist. - A very common and low-risk pattern that the
^/etc($|/)pattern still matches. Confirm the exact source from the message; a read-only single-file mount of/etc/localtimeis a false positive worth recording. Setting theTZenvironment variable instead removes the mount entirely. - The path is outside the fixed list, or it is a named volume rather than a bind mount. Review the full mount list with the first command above, not just the flagged ones.
- Deliberate overlap: this check finds it on any container, the Docker Socket In Containers check looks at running ones, and Writable Volume Mounts escalates when it is writable. Remove the mount and all three clear. A socket proxy still mounts the real socket read-only, so it stays in this check's FAIL; record it as the accepted exception.
