Docker cleanup without surprises
Inspect disk usage first, then remove only the Docker resources you actually intend to discard.
What it is
Docker keeps stopped containers, unused images, build cache, networks, and volumes until you remove them. Cleanup commands reclaim that disk space.
When to use it
Use this process when Docker’s storage has grown unexpectedly, a build host is running low on disk, or you want to understand what can be removed before running a destructive prune.
Where to use it
Run these commands on the Docker host. In production, confirm which volumes and stopped containers still belong to recovery or rollback procedures before deleting anything.
How to use it
Start with an inventory:
docker system df -v
docker ps --all
docker volume ls
Remove stopped containers and dangling image layers first:
docker container prune
docker image prune
docker builder prune
Use the broader command only after reviewing its scope:
docker system prune
Notes and gotchas
Do not add --volumes casually. Unused volumes can still contain the only copy of application data.
docker system prune --all removes every image not currently used by a container, not only dangling layers. That can make the next deployment slower and can remove an image you expected to keep for rollback.