Reclaim Disk Space with Docker System Prune
Docker silently eats your disk space — a single command can reclaim gigabytes.
What
Docker accumulates unused images, stopped containers, dangling volumes, and unused networks over time. The docker system prune command removes all of these unused resources in one sweep. With the -a flag, it also removes images not associated with any container, not just dangling ones.
Why It Matters
Developers often discover Docker has consumed 20-50 GB of disk space without realizing it. Old images, exited containers, and orphaned volumes pile up silently. Regular pruning keeps your system clean and prevents the dreaded 'no space left on device' error during critical builds.
Example
# See how much space Docker is using
docker system df
# Basic prune: removes stopped containers, unused networks,
# dangling images, and dangling build cache
docker system prune
# Aggressive prune: also removes ALL unused images
# and volumes (use with caution)
docker system prune -a --volumes
# Prune with a time filter (remove items older than 24h)
docker system prune --filter "until=24h"
# Prune specific resource types
docker image prune -a # unused images only
docker container prune # stopped containers only
docker volume prune # unused volumes onlyCommon Mistake
Running docker system prune -a --volumes on a production server without first checking what will be removed. This can delete volumes containing database data or images needed for rollbacks.
Quick Fix
Always run docker system df first to see what's using space. On production servers, use targeted prune commands (docker image prune, docker container prune) instead of the nuclear docker system prune -a --volumes.
Key Takeaways
- 1docker system df = see disk usage breakdown
- 2docker system prune = safe cleanup of dangling resources
- 3Add -a to remove ALL unused images (not just dangling)
- 4Add --volumes to include orphaned volumes
- 5On production: use targeted prune, never -a --volumes
Was this tip helpful?
Help us improve the DevOpsPath daily collection