Skip to content

danilovera36/docker-cleanup-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

docker-cleanup-bot

CLI to prune dangling images, stopped containers, and unused volumes/networks. Includes dry-run safety and age-based filtering.

CI Python 3.9+ License: MIT



Features

  • ๐Ÿ” Dry-run by default โ€” always shows what would be deleted before acting
  • ๐Ÿ—‚ Cleans containers, images, volumes, and networks independently
  • โฑ Age-based filtering (--older-than 7d) โ€” don't touch recent objects
  • ๐Ÿ“ฆ Keep-last policy (--keep-last 3) โ€” retain the N most recent image tags
  • ๐Ÿ“Š Space reclaim summary (human-readable sizes)
  • ๐Ÿ–ฅ status subcommand shows total Docker disk usage at a glance
  • ๐Ÿ“‹ JSON output mode for CI pipeline integration

Usage

# Install
pip install docker-cleanup-bot

# Preview what would be cleaned (safe, no deletions)
docker-cleanup clean --dry-run

# Preview only images and containers, skip volumes
docker-cleanup clean --dry-run --no-volumes --no-networks

# Delete everything older than 7 days (with confirmation prompt)
docker-cleanup clean --older-than 7d

# Keep only the 3 most recent tags per image repo
docker-cleanup clean --keep-last 3 --dry-run

# Skip confirmation (for CI pipelines)
docker-cleanup clean --older-than 24h --force

# Show overall Docker disk usage
docker-cleanup status

๐Ÿ“ฆ Installation

pip install docker-cleanup-bot

Or from source:

git clone https://github.com/your-username/docker-cleanup-bot.git
cd docker-cleanup-bot
pip install -e .

๐Ÿ”ง Usage

Commands:
  clean   Scan and remove unused Docker resources.
  status  Show current Docker disk usage.

Options for `clean`:
  --dry-run               Preview without deleting. [default: False]
  --images/--no-images    Include dangling/unused images.
  --containers/--no-containers  Include stopped containers.
  --volumes/--no-volumes  Include unused volumes.
  --networks/--no-networks Include unused networks.
  --older-than DURATION   Only objects older than this (e.g. 24h, 7d).
  --keep-last N           Keep N most recent image tags per repository.
  --force, -f             Skip confirmation prompt.
  --json                  JSON output for CI pipelines.

๐Ÿค– CI/CD Integration

# .github/workflows/cleanup.yml
- name: Docker Cleanup
  run: |
    pip install docker-cleanup-bot
    docker-cleanup clean --older-than 24h --force --json

๐Ÿ”’ Safety

  • Never deletes running containers
  • Never deletes built-in networks (bridge, host, none)
  • Always shows a confirmation prompt unless --force is passed
  • --dry-run mode is 100% read-only

๐Ÿค Contributing

Pull requests are welcome. For major changes, please open an issue first.


๐Ÿ“ License

MIT ยฉ Danilo Vera

About

Smart Docker cleanup CLI with dry-run preview, age filtering, and space reports. Safe by default. ๐Ÿงน

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages