cleanup
rfswift cleanup
Clean up containers and images to free disk space.
Synopsis
rfswift cleanup <subcommand> [OPTIONS]The cleanup command removes old or unused containers and images based on age filters. It provides three subcommands to target specific resource types or clean everything at once.
Subcommands
| Subcommand | Description |
|---|---|
all |
Remove both old containers and images |
containers |
Remove old containers only |
images |
Remove old images only |
Common Options
These options are available on all subcommands (all, containers, images):
| Flag | Description | Default | Example |
|---|---|---|---|
--older-than |
Remove items older than duration | "" |
--older-than 7d |
--force |
Don’t ask for confirmation | false |
--force |
--dry-run |
Show what would be deleted without actually deleting | false |
--dry-run |
The --older-than flag accepts durations such as 24h, 7d, 1m, and 1y.
Subcommand-Specific Options
containers
| Flag | Description | Default | Example |
|---|---|---|---|
--stopped |
Only remove stopped containers | false |
--stopped |
images
| Flag | Description | Default | Example |
|---|---|---|---|
--dangling |
Only remove dangling (untagged) images | false |
--dangling |
--prune-children |
Also remove dependent child images | false |
--prune-children |
Examples
Basic Usage
Clean both containers and images:
rfswift cleanup allPreview what would be deleted:
rfswift cleanup all --dry-runFull cleanup without prompts:
rfswift cleanup all --forceRemove containers only:
rfswift cleanup containersRemove images only:
rfswift cleanup imagesFiltering by Age
Remove containers older than 7 days:
rfswift cleanup containers --older-than 7dRemove images older than 1 month:
rfswift cleanup images --older-than 1mRemove all resources older than 24 hours:
rfswift cleanup all --older-than 24h --forceReal-World Scenarios
Weekly maintenance:
# Remove stopped containers older than a week
rfswift cleanup containers --stopped --older-than 7d --force
# Remove dangling images
rfswift cleanup images --dangling --forceBefore major operations:
# Free space before pulling large images
rfswift cleanup all --force
# 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 image cleanup:
# Remove only dangling images and their children
rfswift cleanup images --dangling --prune-children --forceSafe preview before cleanup:
# See what would be removed without deleting anything
rfswift cleanup all --dry-run
# If the list looks right, run for real
rfswift cleanup all --forceCleanup Strategies
Conservative Strategy
Remove only stopped containers and dangling images:
rfswift cleanup containers --stopped --force
rfswift cleanup images --dangling --forceGood for:
- Production systems
- Careful disk management
- Preserving development environments
Balanced Strategy
Remove older unused resources:
rfswift cleanup all --older-than 7d --forceGood for:
- Regular maintenance
- Development systems
- General cleanup
Aggressive Strategy
Remove everything unused:
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 all --older-than 7d --force to prevent disk space issues. Daily or weekly cleanup keeps your system healthy!--dry-run to preview what will be deleted. This helps avoid accidentally removing resources you still need.containers and images subcommands with their specific flags (--stopped, --dangling, --prune-children) for precise control over what gets removed.