Docker Disk Cleanup for Developers: How to Free Space Without Nuking the Wrong Things
A practical Docker cleanup guide covering images, containers, volumes, build cache, and the commands that free disk space without turning your machine into a mystery afterward.
Why Docker cleanup goes wrong: people either ignore disk growth until their machine gasps for air, or they panic and run destructive prune commands without understanding what will disappear.
Start by seeing where the space went
Run:
docker system dfThis shows usage across:
- images
- containers
- local volumes
- build cache
Do this first. Cleanup is much smarter when you know which category is actually bloated.
Safe-ish first cleanup
Remove stopped containers, dangling networks, unused images, and build cache:
docker system pruneDocker will ask for confirmation.
This is a better first step than swinging directly at volumes.
If images are the real problem
Remove unused images more aggressively:
docker image prune -aBe careful: this removes images not currently used by containers, even if you planned to reuse them soon.
If build cache is huge
Clean builder cache:
docker builder pruneOr more aggressively:
docker builder prune -aThis is often surprisingly effective on machines that build frequently.
Be very careful with volumes
Volumes often contain databases, local state, or data you actually care about.
List them:
docker volume lsRemove one specific volume:
docker volume rm my_volume_nameOnly nuke unused volumes globally if you really mean it:
docker volume pruneThat command can be valid, but it should never be your first reflex on a machine with local databases or test data you still need.
The dangerous “clean everything” pattern
This command is powerful:
docker system prune -a --volumesIt can free a lot of space, but it can also destroy local state you wanted to keep.
Use it only when you understand the blast radius.
A calmer cleanup sequence
If your machine is bloated, the safest order is usually:
- inspect with
docker system df - prune stopped containers and dangling artifacts
- target the real offender: images, builder cache, or volumes
- re-check usage before doing anything more destructive
That sequence frees a surprising amount of space without turning local development into archaeology.
If you use Docker Desktop, remember that caches and image layers can grow quietly in the background even when your active project is small. Periodic cleanup is normal maintenance, not evidence that your setup is broken.
The real goal is not “make the number go to zero.” It is “free enough space without damaging the environments you still need.” Developers get into trouble when they treat every removable artifact as equally disposable. In practice, containers, images, build cache, and volumes have very different risk profiles.
Once you respect those differences, cleanup becomes much less scary and much more effective.
That is the difference between routine maintenance and accidental self-sabotage.
It is a small discipline, but it keeps local Docker from turning into an opaque black box.
Final recommendation
Good cleanup order:
- inspect with
docker system df - prune stopped and dangling resources
- target the real offender: images, cache, or volumes
- avoid volume deletion unless you are certain
Docker cleanup should feel deliberate, not emotional. The goal is to free space without making tomorrow’s local environment harder to understand.