The check first builds an allow-list of UIDs: it reads .Config.User from every container on the host, takes the part before any colon, and keeps only the entries that are purely numeric. Then, for each /var/lib/docker/volumes/*/_data directory, it takes the owning UID with stat -c '%u' run through as_root. A volume is reported only when both conditions hold: the UID resolves to no host account through getent passwd, and it is absent from that container allow-list. Any volume meeting both is a WARN listing volume:uid for up to five of them; no volume meeting both is the PASS.
Needs root or sudo and an existing /var/lib/docker/volumes; otherwise SKIP (a custom data-root or a rootless daemon therefore SKIPs). For each */_data directory it takes the owner UID and reports it only if that UID has no /etc/passwd entry and matches no numeric .Config.User of any container on the host. That second condition is what stops normal image UIDs (postgres 999, nginx 101) from being reported. At most 5 volumes are listed. The finding is about stale data, not permissions - a volume owned by an unknown UID is usually left over from a removed image, which is why it is a WARN and the message says to confirm before deleting.
| Result | When | What it means |
|---|---|---|
| SKIP | No root / directory absent | Nothing was verified. No volume ownership was read at all. |
| WARN | Volumes owned by a UID nobody uses | At least one volume is owned by a UID that resolves to no host user and no container's configured user, which usually means stale data from a removed image. Confirm each before deleting it. |
| PASS | Every volume's owner is a host user or a configured container user | Every volume owner resolves to something known on this host, so nothing looks orphaned. This says nothing about the modes on that data. |
Data left behind by removed containers/images may hold secrets or backups that nobody audits, and a future account or container that reuses that UID silently inherits it. Housekeeping and least privilege; NIST SP 800-190 4.4.4 (persistent storage).
- Images that drop privileges inside the entrypoint (postgres runs as UID 999, nginx as 101, redis as 999) have an empty
.Config.User, so those UIDs are not inCUIDS. If the host also has no user with that UID, their volumes are flagged as orphans even though they are in active use. This is a common false positive; the message already says "confirm before deleting". - A container configured with a user name (
USER node,--user www-data) adds nothing to the allow-list, because only purely numeric values are kept. Its volume is reported unless the host also has an account with that UID. - A rootless daemon keeps its volumes under
~/.local/share/docker, so this check SKIPs. Withuserns-remapthe daemon stores volumes under/var/lib/docker/<uid>.<gid>/volumes, so the check either SKIPs or reads what is left in/var/lib/docker/volumesfrom before remapping was turned on, and those leftovers really are unused. - Anonymous volumes are handled by the Anonymous/Dangling Volumes check.
Find out whether anything uses the volume
Any container listed, running or stopped, still references it.
sh docker ps -a --filter volume=<name> --format '{{.Names}}\t{{.Status}}'If a container uses it, make the UID known
The data is live, so leave it where it is. Either give the UID a host account with no login, or set the container's user to the numeric UID so it joins the check's allow-list. Both clear the finding. Use the UID the WARN message printed after the volume name; 999 below is an example.
sh sudo useradd --system --no-create-home --shell /usr/sbin/nologin --uid 999 volume-999Or in Compose,
user: "999:999"on the service. Test that one first: some images expect to start as root and only drop to their own user in the entrypoint.If nothing uses it, look at the data
sh docker run --rm -v <name>:/mnt:ro alpine ls -la /mntsudo du -sh /var/lib/docker/volumes/<name>/_dataBack it up, then remove it
sh docker run --rm -v <name>:/src:ro -v "$PWD":/backup alpine tar czf /backup/<name>.tgz -C /src .docker volume rm <name>
# Owner of every volume, with the name resolved where possible:# (inside sudo sh -c, because your own shell cannot expand a glob under /var/lib/docker)sudo sh -c "stat -c '%n %u %U' /var/lib/docker/volumes/*/_data"# The UIDs containers are configured to run as (the check's allow-list):docker ps -aq | xargs -I{} docker inspect -f '{{.Config.User}}' {} | cut -d: -f1 | grep -E '^[0-9]+$' | sort -u# Before deleting anything, find out whether a volume is referenced:docker volume ls -f dangling=truedocker ps -a --filter volume=<name>sudo du -sh /var/lib/docker/volumes/<name>/_data- There is no unprivileged fallback, and membership of the
dockergroup is not enough: it reaches the daemon, not/var/lib/docker/volumes. Run the audit as root or give the audit account sudo. - Docker keeps its data somewhere else.
docker info --format '{{.DockerRootDir}}'shows where: a customdata-root, a rootless daemon oruserns-remapall land here. Run thestatcommand from the verify step against the real path. - Happens when the container declares no
.Config.User(so it contributes no UID to the allow-list) while its process still writes as an image-internal UID. Confirm withdocker ps -a --filter volume=<name>; if a container uses it, this is a false positive to record, not data to delete. - Check it is dangling and look at the size and contents before removing:
docker volume inspect <name>, thendocker run --rm -v <name>:/mnt alpine ls -la /mnt. Only thendocker volume rm <name>. docker volume prunedeletes every unused anonymous volume at once, anddocker volume prune --allevery unused named one too, including a database whose container was recreated under a different name. Confirm each one first.- The message truncates at 5. Use the
statcommand above for the full picture. - Ownership here is a staleness signal. For actual exposure, see World-Writable Volumes and Volume Directory Permissions.
