Skip to main content

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

License: MIT Python 3.8+ Docker

Why Docker Cleanup Pro?

If you're a Docker user, you know the pain:

  • Docker fills up disk space fast
  • docker system prune is 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

Support

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docker_cleanup_pro-1.0.0.tar.gz (36.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docker_cleanup_pro-1.0.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file docker_cleanup_pro-1.0.0.tar.gz.

File metadata

  • Download URL: docker_cleanup_pro-1.0.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

Hashes for docker_cleanup_pro-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8d27284de1a373e449f713507828790d27e2ed698b196fe9d682ec9cfdc8a686
MD5 48e2fd7c42072dde8de1b5df7ad3235a
BLAKE2b-256 8195fcddb0d468b18c93efea9d383c8e74dc11e505a422d3884b8468fe2a325e

See more details on using hashes here.

File details

Details for the file docker_cleanup_pro-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for docker_cleanup_pro-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 23c873b82471c252f9a05aa885c313fec74df9c7da6114e2c4b8cde8f84b7e08
MD5 f24327f5394d5f829cbb279a84d21eef
BLAKE2b-256 d98148aca6bcab2b112eb3eb1e0182efd433b5b709d3e8fe0dd14b98f0c2f138

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page