Smart Docker cleanup that saves disk space without breaking things
Project description
Docker Cleanup Pro ⭐
Smart Docker cleanup that saves disk space without breaking things
Why Docker Cleanup Pro?
If you're a Docker user, you know the pain:
- Docker fills up disk space fast
docker system pruneis scary (it removes too much!)- Developers waste hours managing Docker storage
Docker Cleanup Pro solves this with safe, smart cleanup that:
- ✅ Removes unused images while keeping recent versions
- ✅ Cleans dangling volumes safely
- ✅ Removes old containers intelligently
- ✅ Shows exactly what was cleaned and how much space was saved
- ✅ Includes dry-run mode to preview changes
- ✅ Saves rollback state for safety
Quick Start
Installation
# Install via pip
pip install docker-cleanup-pro
# Or install from source
git clone https://github.com/ahmad0303/docker-cleanup-pro.git
cd docker-cleanup-pro
pip install -e .
Basic Usage
# Safe cleanup (recommended for first-time users)
docker-cleanup --safe
# Dry run to see what would be removed
docker-cleanup --dry-run
# Aggressive cleanup (removes more)
docker-cleanup --aggressive
Features
Safe Mode (Recommended)
Removes unused Docker resources while keeping your system stable:
docker-cleanup --safe
What it does:
- Keeps last 3 versions of each image
- Removes containers stopped 7+ days ago
- Cleans dangling volumes only
- Removes build cache
- Shows space saved with detailed summary
Aggressive Mode
For maximum cleanup when you need disk space NOW:
docker-cleanup --aggressive
What it does:
- Keeps only 1 version of each image
- Removes containers stopped 1+ day ago
- More aggressive cleanup overall
Dry Run Mode
Preview what would be removed without making changes:
docker-cleanup --dry-run
Perfect for understanding the impact before running cleanup!
Selective Cleanup
Clean only specific resources:
# Only clean images
docker-cleanup --images
# Only clean containers
docker-cleanup --containers
# Only clean volumes
docker-cleanup --volumes
# Only clean build cache
docker-cleanup --build-cache
# Combine multiple options
docker-cleanup --images --build-cache
Custom Configuration
Fine-tune cleanup behavior:
# Keep 5 versions of each image
docker-cleanup --safe --keep-versions 5
# Keep containers from last 14 days
docker-cleanup --safe --keep-recent-days 14
# Combine custom settings
docker-cleanup --keep-versions 2 --keep-recent-days 3
Example Output
Docker Cleanup Pro
==================================================
Running in SAFE mode
🖼️ Cleaning up images...
✓ Removed: myapp:v1.0.0 (245.32 MB)
✓ Removed: myapp:v0.9.0 (238.15 MB)
x Skipped (in use): myapp:latest
✓ Removed dangling: sha256:abc123 (15.48 MB)
📦 Cleaning up containers...
✓ Removed: old_container_1 (status: exited)
✓ Removed: test_container (status: exited)
💿 Cleaning up volumes...
✓ Removed: orphaned_volume_abc123
🏗️ Cleaning up build cache...
✓ Removed build cache (1.23 GB)
==================================================
📊 Cleanup Summary
==================================================
Images removed: 4
Containers removed: 2
Volumes removed: 1
Space saved: 1.73 GB
💾 Rollback info saved to: /home/user/.docker-cleanup-rollback.json
==================================================
✅ Cleanup completed successfully!
Safety Features
Rollback Support
Every cleanup operation saves rollback information:
# Rollback state saved automatically
~/.docker-cleanup-rollback.json
Confirmation Prompts
Non-dry-run operations require confirmation:
⚠️ This will remove Docker resources. Continue? [y/N]:
Smart Version Keeping
Automatically keeps the most recent versions of images by creation date.
Protected Resources
- Running containers are never removed
- Recently stopped containers are kept (configurable)
- In-use images are automatically skipped
- Named volumes require explicit dangling status
Advanced Usage
CI/CD Integration
Use in automated pipelines:
# GitHub Actions example
- name: Cleanup Docker
run: |
docker-cleanup --safe --keep-versions 2
Cron Jobs
Schedule regular cleanup:
# Add to crontab (weekly cleanup)
0 2 * * 0 /usr/local/bin/docker-cleanup --safe
Docker-in-Docker
Works in Docker-in-Docker (DinD) environments:
FROM docker:dind
RUN apk add --no-cache python3 py3-pip
RUN pip3 install docker-cleanup-pro
Requirements
- Python: 3.8 or higher
- Docker: Any recent version
- Permissions: Access to Docker daemon (usually requires sudo/root or docker group membership)
Contributing
Contributions are welcome! Please check out our Contributing Guidelines.
Development Setup
# Clone the repository
git clone https://github.com/ahmad0303/docker-cleanup-pro.git
cd docker-cleanup-pro
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Format code
black docker_cleanup/
# Run linting
flake8 docker_cleanup/
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built with the excellent Docker SDK for Python
- Inspired by the need for safer Docker cleanup workflows
Support
- Issues: GitHub Issues
Star History
If you find this project useful, please consider giving it a star! It helps others discover it.
Made with ❤️ for the Docker community
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file docker_cleanup_pro-1.1.0.tar.gz.
File metadata
- Download URL: docker_cleanup_pro-1.1.0.tar.gz
- Upload date:
- Size: 36.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20e7984f041dd1954fff4b0fad600ef588be6086422b8387759fd17bf7d2ca87
|
|
| MD5 |
6ba396aaae9ff5a7d598ddfa5977b168
|
|
| BLAKE2b-256 |
afb3594edd8f5b4f9ae14f90122e60dbe7a1335a069b6c4cac3c97b266fb6cff
|
File details
Details for the file docker_cleanup_pro-1.1.0-py3-none-any.whl.
File metadata
- Download URL: docker_cleanup_pro-1.1.0-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef29dd666d3d137e24311cb20ca6cdd353f3f51f0584bcad1bb8d616d210fd1a
|
|
| MD5 |
cc215f33aea3af69a2fa1594de4a7182
|
|
| BLAKE2b-256 |
6c67d3691c33f67a4ef47c39e8c2ea5dd51ef0f35ce007b106f93639fa988166
|