Skip to content

Docker audit fix · Volume Permissions

How to Clean & Remove Dangling Docker Volumes on VPS

A dangling Docker volume is one no container references any more, and it keeps whatever the container that made it wrote: database files, uploads, secrets. List them with docker volume ls -f dangling=true, review each, then prune.

Hiren KalariyaHiren KalariyaLast reviewed anonymous-dangling-volumes
CtrlOpsAnonymous/Dangling VolumesLOW

What did your audit say?

WARN · when the audit printed

One or more dangling volumes

At least one volume is unreferenced and may still hold data from a container that was removed. The message names up to five of them.

Severity
Low
Needs root or sudo
Yes
Results it can return
WARN · SKIP · PASS
Check in this audit
6 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.

The check runs docker volume ls -f dangling=true --format '{{.Name}}' through the dk helper and counts the non-empty lines that come back. The dangling=true filter is Docker's own definition of a volume that no container currently references, so that name list is the entire input: no size, label, mountpoint or content is read. Zero names is the PASS; one or more is a WARN, with at most the first five names quoted in the message and the count itself complete.

Needs the docker binary and daemon access; otherwise SKIP. It runs a single command - docker volume ls -f dangling=true - which lists volumes no container currently references, and reports at most 5 by name. "Dangling" includes both anonymous volumes left behind when a container was removed and named volumes whose containers no longer exist; the check does not distinguish them, look at their size, or inspect their contents. It is a hygiene and stale-data signal rather than an exposure, hence LOW severity - but a dangling volume can still hold a full database from a removed container.

What each result means
ResultWhenWhat it means
SKIPDocker missing / daemon unreachableNothing was verified. No volume list was ever retrieved, so dangling volumes may well exist unreported.
PASSNoneEvery volume on this host is referenced by at least one container, so there is no orphaned volume data to review.
WARNOne or more dangling volumesAt least one volume is unreferenced and may still hold data from a container that was removed. The message names up to five of them.

Dangling volumes (no container references them) accumulate from docker run without --rm, recreated Compose services, and images with VOLUME directives. They hold stale data (database files, uploads, secrets) that nobody backs up, rotates, or audits, and they consume disk. Housekeeping per NIST SP 800-190 4.4.4.

  • A named volume you created in advance for a service that is not yet deployed is "dangling" until the container exists.
  • Compose down without -v leaves named volumes by design (so data survives); they are only dangling if no container references them at audit time, which happens between down and up.
  • dangling=true also includes named volumes, not just anonymous hashes.
  1. List them with their size

    sh
    for v in $(docker volume ls -qf dangling=true); do  printf '%s\t%s\n' "$v" "$(sudo du -sh "$(docker volume inspect -f '{{.Mountpoint}}' "$v")" 2>/dev/null | cut -f1)"done

  2. Look inside the ones you do not recognise

    The labels name the Compose project and volume that created a volume, if any; anonymous volumes have a 64-character hash for a name and usually no labels.

    sh
    docker volume inspect <name>          # check Labels and Mountpointdocker run --rm -v <name>:/mnt:ro alpine ls -la /mnt

  3. Back up anything worth keeping, then remove

    sh
    docker run --rm -v <name>:/src:ro -v "$PWD":/backup alpine tar czf /backup/<name>.tgz -C /src .docker volume rm <name>

    Once every remaining dangling volume is one you are sure about, a prune removes them in one go. Without --all it removes only anonymous volumes; --all (Docker 23 and later) adds named ones.

    sh
    docker volume prunedocker volume prune --all

  4. Stop new ones piling up

    Start throwaway containers with docker run --rm, which removes their anonymous volumes with them. Give volumes names in Compose, so a recreated service reuses its volume instead of leaving the old one behind.

sh
docker volume ls -f dangling=true# expected: no output, or only volumes you decided to keep# Space the remaining volumes use, and how much is reclaimable:docker system df

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 volume ls, which fails quietly and returns nothing, and an empty list is read as zero dangling volumes. On a host where Docker may be down, run sudo docker volume ls before trusting that PASS.
  • Do not. docker volume prune deletes every dangling volume irreversibly, and a database volume becomes "dangling" the moment its container is recreated under a different name or removed during a deploy. Check size and contents with the commands above first.
  • An image with a VOLUME instruction creates a fresh anonymous volume on every docker run without --rm or an explicit -v. Either use docker run --rm, or give the volume a name so it is reused rather than orphaned each time.
  • Dangling volumes are only one source. Check images and build cache too: docker system df, then docker image prune / docker builder prune.
  • The message truncates at 5; the count is complete. Use docker volume ls -qf dangling=true for the full list.

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