cleanup
rfswift cleanup
Automated cleanup of Docker resources to free disk space.
Synopsis
rfswift cleanup [OPTIONS]The cleanup command removes unused Docker resources including stopped containers, dangling images, unused volumes, and build cache. This helps maintain disk space and keep your Docker environment clean.
Options
| Flag | Description | Default | Example |
|---|---|---|---|
--all |
Remove all unused resources | false | --all |
--containers |
Remove stopped containers only | false | --containers |
--images |
Remove unused images only | false | --images |
--volumes |
Remove unused volumes only | false | --volumes |
--force |
Skip confirmation prompts | false | --force |
Examples
Basic Usage
Interactive cleanup (asks confirmation):
rfswift cleanupFull cleanup without prompts:
rfswift cleanup --all --forceRemove stopped containers only:
rfswift cleanup --containersRemove unused images only:
rfswift cleanup --imagesReal-World Scenarios
Weekly maintenance:
# Clean up stopped containers and dangling images
rfswift cleanup --containers --imagesBefore major operations:
# Free space before pulling large images
rfswift cleanup --all
# Then pull new images
rfswift images pull -i penthertz/rfswift_noble:sdr_fullEmergency disk space recovery:
# Aggressive cleanup when disk is full
rfswift cleanup --all --force
# Check space recovered
df -hSelective cleanup:
# Keep running containers, remove images only
rfswift cleanup --images --forcePost-development cleanup:
# After testing, clean up test containers and images
rfswift cleanup --containers --imagesWhat Gets Cleaned Up
Cleanup Targets
| Resource | Description | When Removed |
|---|---|---|
| Stopped containers | Containers not running | Always safe |
| Dangling images | Untagged images (<none>:<none>) |
Always safe |
| Unused images | Images not used by any container | Safe if not needed |
| Build cache | Docker build layer cache | Safe but slows rebuilds |
| Networks | Unused custom networks | Usually safe |
Safety Levels
Safe to remove:
- โ Stopped containers (can recreate)
- โ Dangling images (no tag, no use)
- โ Build cache (recreated on next build)
- โ Unused networks
Caution required:
- โ ๏ธ Unused images (may need later)
- โ ๏ธ Unused volumes (may contain data)
Never removed:
- โ Running containers
- โ Images used by running containers
- โ Volumes attached to containers
Cleanup Strategies
Conservative Strategy
Remove only clearly unused resources:
# Stopped containers only
rfswift cleanup --containers --forceGood for:
- Production systems
- Careful disk management
- Preserving development environments
Balanced Strategy
Remove most unused resources:
# Containers and images
rfswift cleanup --allGood for:
- Regular maintenance
- Development systems
- General cleanup
Aggressive Strategy
Remove everything unused:
# Full cleanup
rfswift cleanup --all --forceGood for:
- Emergency space recovery
- Fresh start scenarios
- CI/CD systems
Troubleshooting
Cleanup Not Freeing Space
Problem: Ran cleanup but disk usage still high
Solutions:
# Check what's using space
docker system df -v
# Try more aggressive cleanup
docker system prune -a -f --volumes
# Check for large log files
find /var/lib/docker -name "*.log" -size +100M
# Check other disk usage
du -sh /var/lib/docker/*
# May need to clean Docker logs
truncate -s 0 /var/lib/docker/containers/*/*-json.logPermission Denied
Problem: Cleanup fails with permission errors
Solutions:
# Use sudo
sudo rfswift cleanup --all --force
# Or add user to docker group
sudo usermod -aG docker $USER
newgrp docker
# Then retry
rfswift cleanup --all --forceImportant Container Removed
Problem: Accidentally removed needed container
Solutions:
# Check backups
ls ~/docker-backups/
# Restore from export
rfswift import container -i backup.tar.gz -n restored_container
# Recreate from image if no backup
rfswift run -i penthertz/rfswift_noble:sdr_full -n recreated_container
# Lesson: Always export important containers before cleanup
rfswift export container -c important -o backup.tar.gzRelated Commands
last- List containers before cleanupremove- Remove specific containersdelete- Remove specific imagesimages- Check images before cleanup
rfswift cleanup --containers --images --force to prevent disk space issues. Daily or weekly cleanup keeps your system healthy!--volumes flag removes ALL unused volumes, which may contain important data. Always check volumes before removing them, and backup any important data!cleanup removes stopped containers and dangling images only - the safest cleanup. Use --all for more aggressive cleanup when you need more space.