Cleanup and Maintenance
This guide covers devbox’s cleanup and maintenance features to keep your development environment healthy and optimized.
Cleanup Command
Section titled “Cleanup Command”The devbox cleanup command helps maintain a clean system by removing various Docker resources and devbox artifacts.
Interactive Cleanup
Section titled “Interactive Cleanup”devbox cleanupThis opens an interactive menu with the following options:
- Clean up orphaned devbox boxes - Remove boxes not tracked in config
- Remove unused Docker images - Remove dangling and unused images
- Remove unused Docker volumes - Remove unused volumes
- Remove unused Docker networks - Remove unused networks
- Run Docker system prune - Comprehensive cleanup of all unused resources
- Clean up everything - Combines options 1-4
- Show system status - Display disk usage and system information
Command-Line Flags
Section titled “Command-Line Flags”# Specific cleanup tasksdevbox cleanup --orphaned # Remove orphaned boxes onlydevbox cleanup --images # Remove unused images onlydevbox cleanup --volumes # Remove unused volumes onlydevbox cleanup --networks # Remove unused networks onlydevbox cleanup --system-prune # Run docker system prunedevbox cleanup --all # Clean up everything
# Safety and informationdevbox cleanup --dry-run # Show what would be cleaned (no changes)devbox cleanup --force # Skip confirmation promptsExamples
Section titled “Examples”# See what would be cleaned without making changesdevbox cleanup --dry-run --all
# Clean only orphaned boxesdevbox cleanup --orphaned
# Comprehensive cleanup with confirmationdevbox cleanup --all
# Quick cleanup without promptsdevbox cleanup --all --forceMaintenance Command
Section titled “Maintenance Command”The devbox maintenance command provides system health monitoring, updates, and repair functionality.
Interactive Maintenance
Section titled “Interactive Maintenance”devbox maintenanceThis opens an interactive menu with these options:
- Check system status - Show Docker status, projects, and disk usage
- Perform health check - Check health of all projects
- Update system packages - Update packages in all boxes
- Restart stopped boxes - Start any stopped devbox boxes
- Rebuild all boxes - Recreate boxes from latest base images
- Auto-repair common issues - Automatically fix detected problems
- Full maintenance - Combines health check, updates, and restarts
Command-Line Flags
Section titled “Command-Line Flags”# Individual maintenance tasksdevbox maintenance --status # Show detailed system statusdevbox maintenance --health-check # Check health of all projectsdevbox maintenance --update # Update all boxesdevbox maintenance --restart # Restart stopped boxesdevbox maintenance --rebuild # Rebuild all boxesdevbox maintenance --auto-repair # Auto-fix common issues
# Control flagsdevbox maintenance --force # Skip confirmation promptsExamples
Section titled “Examples”# Check system healthdevbox maintenance --health-check
# Update all boxesdevbox maintenance --update
# Rebuild all boxes (with confirmation)devbox maintenance --rebuild
# Quick full maintenance without promptsdevbox maintenance --force --health-check --update --restartUpdate Command
Section titled “Update Command”Use the devbox update command to rebuild environment boxes from the latest base images. This is the recommended way to apply upstream image updates or configuration changes that affect the base image or setup commands.
Why use devbox update?
Section titled “Why use devbox update?”- Pulls the newest base image(s)
- Recreates the box with your current
devbox.jsonconfiguration - Automatically runs a full system update inside the box
- Re-runs your
setup_commandsto ensure tools are present - Preserves your project files on the host at
~/devbox/<project>/
# Update a single projectdevbox update myproject
# Update all projectsdevbox updateWhen to use maintenance vs update
Section titled “When to use maintenance vs update”devbox maintenance --update: Update system packages inside existing boxesdevbox update: Rebuild boxes from the latest base images and re-apply configuration
If you’re changing base_image in devbox.json or want to ensure you are using the latest upstream image, use devbox update.
Health Checks
Section titled “Health Checks”The health check system monitors:
- Box Status: Whether boxes are running or stopped
- Box Responsiveness: Whether boxes respond to commands
- Workspace Directories: Whether project directories exist
- Configuration Files: Whether devbox.json files are valid
Health check results show:
- ✅ Healthy: Box running and responsive
- ⚠️ Unhealthy: Box stopped or unresponsive
- ❌ Missing: Box or workspace missing
Auto-Repair
Section titled “Auto-Repair”The auto-repair feature automatically fixes common issues:
- Missing workspace directories: Creates missing project directories
- Missing boxes: Recreates boxes from configuration
- Stopped boxes: Starts stopped boxes
- Unresponsive boxes: Restarts boxes that don’t respond
System Updates
Section titled “System Updates”The update feature:
- Runs
apt update -yto refresh package lists - Runs
apt full-upgrade -yto install updates - Runs
apt autoremove -yto remove unnecessary packages - Runs
apt autocleanto clean package cache
Updates are applied to all tracked boxes that are running or can be started.
Box Rebuilding
Section titled “Box Rebuilding”The rebuild feature:
- Stops and removes existing boxes
- Pulls latest base images
- Recreates boxes with current configuration
- Runs system updates
- Executes setup commands from devbox.json
- Sets up devbox environment
Monitoring
Section titled “Monitoring”System Status
Section titled “System Status”# Quick status overviewdevbox list
# Detailed system informationdevbox maintenance --status
# Docker resource usagedocker system dfBox Health
Section titled “Box Health”# Check all project healthdevbox maintenance --health-check
# Check specific boxdocker inspect devbox_myproject
# View box logsdocker logs devbox_myprojectResource Usage
Section titled “Resource Usage”# Live box statsdocker stats
# Disk usage by typedocker system df -v
# List all devbox boxesdocker ps -a --filter "name=devbox_"