Docker cleanup cheat sheet: reclaim disk
Docker is generous with disk: every stopped container, every replaced image layer and every unused volume stays on disk until you remove it. The result is machines that mysteriously fill up. The fix is a small set of commands, run in order from look to delete.
The rule of thumb: start with docker system df to see what is actually using space, then prune narrowly before you prune everything. A dangling image is an untagged <none>:<none> layer left behind when a tag is reused — those are always safe to remove.
Published
See what is using space
# Summary of disk usage by category
docker system df
# Verbose: break it down per image/container/volume
docker system df -v
# Live memory/CPU per running container
docker stats --no-stream
Prune, from narrow to everything
| Command | Removes |
|---|---|
| docker container prune | all stopped containers |
| docker image prune | dangling images only (untagged <none>:<none>) |
| docker image prune -a | all images not used by at least one container (keeps nothing spare) |
| docker volume prune | volumes not referenced by any container |
| docker network prune | custom networks not used by any container |
| docker builder prune | the build cache (add --all to clear it completely) |
| docker system prune | stopped containers + dangling images + unused networks + build cache |
| docker system prune -a --volumes | everything above PLUS all unused images and unused volumes — the nuclear option |
Remove everything (careful)
# Stop every running container
docker stop $(docker ps -q)
# Remove every container (add -f to skip the stop step)
docker rm $(docker ps -aq)
# Remove every image
docker rmi $(docker images -q)
# Modern, safer spellings of the same idea:
docker container prune -f
docker image prune -a -f
docker system prune -a deletes every image not currently backing a running or stopped container, so a later docker run of a previously-built image has to re-pull or re-build it. Adding --volumes also deletes data volumes — the only loss in this sheet that cannot be recreated. The safe sequence for a nearly-full host: docker system df, then docker container prune, then docker image prune, and only reach for -a --volumes when you have confirmed nothing valuable is left.Why is Docker using so much disk?
- Dangling images. Every
docker buildthat reuses a tag orphans the previous image as an untagged<none>:<none>layer.docker image pruneremoves exactly these. - Stopped containers. Every
docker runwithout--rmleaves a stopped container behind, and each one keeps its writable layer. Use--rmfor one-off jobs or prune stopped containers regularly. - Build cache. Docker caches each Dockerfile layer to make rebuilds fast, and that cache grows.
docker builder pruneclears it; rebuilds get slower until the cache rebuilds. - Volumes. Named volumes are never touched by image/container prune, so orphaned database volumes from deleted projects pile up.
docker volume pruneis the only thing that removes them. - Logs. A container that logs heavily grows its JSON log file, governed by the logging driver's
max-size/max-fileoptions — configure them on the daemon or per-container if a single container balloons.
References
- docker system df — the official disk-usage command.
- docker system prune — what each prune variant removes.
FAQ
How do I remove all stopped containers?
docker container prune removes every stopped container in one step (add -f to skip the confirmation). The classic one-liner equivalent is docker rm $(docker ps -aq), which stops nothing itself — combine with docker stop $(docker ps -q) to clear running containers too.
What is a dangling image?
A dangling image is an image with no tag, shown as
How do I clean up Docker disk space safely?
Start with docker system df to see what is using space. Then docker container prune (stopped containers), docker image prune (dangling images), and docker builder prune (build cache) — none of these delete volumes or images still in use. Use docker system prune -a --volumes only when you also want to drop unused images and data volumes.
Does pruning remove my volumes?
No — except when you add --volumes to docker system prune, or run docker volume prune directly. Plain image/container prune never touches volumes, which is intentional: volumes hold the persistent data. That is also why orphaned volumes from deleted projects are the most common source of hidden disk use.
Related tools
- IPv4 subnet calculator — break any CIDR block into network, range, broadcast and usable hosts.
- IP range to CIDR — turn an arbitrary address range into its minimal covering CIDR blocks.
- VLSM calculator — split a block into right-sized subnets by host requirements.