🗑️ Your Disk is Full of Dead Containers
Stopped containers, unused images, unused volumes — they eat disk space. docker system prune cleans everything in one command.
📝 Prune Commands
# Clean everything (containers, images, networks, build cache)
docker system prune -a --volumes
# Stop and remove all stopped containers
docker container prune
# Remove unused images (dangling and unreferenced)
docker image prune -a
# Remove unused volumes
docker volume prune
# Remove unused networks
docker network prune
# Remove build cache
docker builder prune
# See disk usage
docker system df
# Auto-prune (Docker Desktop settings)
# Settings → Docker Engine → add: "builder": { "gc": { "enabled": true } }
🎯 Scheduled Cleanup (cron)
# Weekly cleanup script #!/bin/bash # /usr/local/bin/docker-cleanup.sh echo "Starting Docker cleanup at $(date)" docker system prune -af --volumes echo "Cleanup complete" # Add to crontab (runs every Sunday at 2 AM) 0 2 * * 0 /usr/local/bin/docker-cleanup.sh >> /var/log/docker-cleanup.log 2>&1
✅ Selective Pruning
- –filter: Prune only old items (until=24h)
- –force / -f: Skip confirmation prompt
- –all / -a: Remove all unused images (not just dangling)
- –volumes: Include volumes (be careful!)
💡 Disk Saving Tips
- Use –rm flag with docker run (auto-remove after exit)
- Set log rotation: docker run –log-opt max-size=10m –log-opt max-file=3
- Use smaller base images (alpine, slim)
- Multi-stage builds reduce final image size
“120GB disk showed 5GB free. docker system df revealed 80GB of unused images. docker system prune -a freed 75GB. Disk space recovered in seconds.”
