Docker Image Cleanup
Overview
Docker images accumulate over time and can consume significant disk space. These commands help safely remove unused images.
Basic Commands
Remove individual images
docker rmi <image-id>
docker rmi <image-name>:<tag>
Remove unused images
# Only dangling images (without tags)
docker image prune
# All unused images
docker image prune -a
# Without confirmation prompt
docker image prune -a -f
Filter by age
# Images older than 24 hours
docker image prune -a --filter "until=24h"
# Images older than 7 days
docker image prune -a --filter "until=168h"
System-wide cleanup
# Images, containers and networks - NO volumes
docker system prune -a
# With automatic confirmation
docker system prune -a -f
Useful checks
# Show disk usage
docker system df
# Show what would be deleted (dry-run)
docker image prune -a --dry-run
Important notes
- Volumes are never deleted with these commands
- Flag
-aremoves images with tags that are not in use - Without
-aonly dangling images are removed - Running containers and their images remain untouched
No comments to display
No comments to display