Analyze Docker resource usage and clean up containers, images, volumes, and build cache with preview and confirmation (macOS only)
Analyzes Docker resource usage and cleans up containers, images, volumes, and build cache with preview and confirmation
/plugin marketplace add irfansofyana/my-claude-code-marketplace/plugin install sys-maint@my-claude-code-marketplaceIMPORTANT: This command is designed and tested for macOS only. It requires Docker to be installed and running.
Your task is to help the user clean up Docker resources safely by analyzing current usage, showing a preview of what will be removed, getting explicit confirmation, and then executing the cleanup operations.
First, gather the current Docker resource usage by running:
!docker system df -v
This will show you disk usage for images, containers, volumes, and build cache.
Analyze the Docker system and present a clear summary to the user:
Parse the output from docker system df -v to extract:
Run additional analysis commands:
docker ps -a -f status=exited -q | wc -ldocker images -f dangling=true -q | wc -ldocker volume ls -f dangling=true -q | wc -lPresent the analysis to the user in a clear, formatted table:
Docker Resource Analysis
========================
Resource Type | Total Size | Reclaimable | Count
--------------------|------------|-------------|-------
Images | X.XX GB | X.XX GB | X items
Containers | X.XX GB | X.XX GB | X stopped
Volumes | X.XX GB | X.XX GB | X unused
Build Cache | X.XX GB | X.XX GB | -
Total Reclaimable Space: X.XX GB
Show the user exactly what will be removed:
List stopped containers (if any):
docker ps -a -f status=exited --format "table {{.ID}}\t{{.Names}}\t{{.Status}}"List dangling images (if any):
docker images -f dangling=true --format "table {{.ID}}\t{{.Repository}}\t{{.Size}}"List unused volumes (if any):
docker volume ls -f dangling=true --format "table {{.Name}}\t{{.Driver}}"Show build cache details:
docker buildx du --verbose (or indicate that build cache will be cleared)Present cleanup options to the user:
What would you like to clean up?
1. Clean All (Recommended)
- Remove all stopped containers
- Remove all dangling images
- Remove all unused volumes
- Clear build cache
- Estimated space freed: X.XX GB
2. Selective Cleanup
- Choose specific resource types to clean
3. Cancel
- Exit without making changes
Ask the user explicitly: "Which option would you like? (Enter 1, 2, or 3)"
Wait for the user's response before proceeding.
Based on the user's choice:
Execute these commands in sequence, showing progress for each:
Remove stopped containers:
docker container prune -f
Report: "✓ Removed stopped containers"
Remove dangling images:
docker image prune -f
Report: "✓ Removed dangling images"
Remove unused volumes:
docker volume prune -f
Report: "✓ Removed unused volumes"
Clear build cache:
docker builder prune -f
Report: "✓ Cleared build cache"
Ask the user which resource types to clean:
Then execute only the selected cleanup commands.
Respond with: "Docker cleanup cancelled. No changes were made."
After cleanup completes:
Run final analysis:
docker system df
Calculate and show space freed:
Present final report:
Docker Cleanup Complete!
========================
Space Reclaimed: X.XX GB
Current Docker Disk Usage:
- Images: X.XX GB
- Containers: X.XX GB
- Volumes: X.XX GB
- Build Cache: X.XX GB
Next Steps:
- Run this command periodically to maintain disk space
- Consider removing unused images: `docker image prune -a` (removes all unused images, not just dangling)
- Monitor with: `docker system df`
If any command fails:
docker ps to see running containers"If Docker is not installed or not running:
Success indicators:
Safety checks: