Container image pruning script that supports both Docker Hub and GitHub Container Registry (GHCR).
usage: main.py [-h] --container CONTAINER
[--registry {ghcr, dockerhub, all}]
[--verbose] [--dry-run]
(--prune-untagged-age DAYS | --prune-all-untagged | --keep-latest COUNT)To use the script, you need to set up environment variables for authentication. The script supports both Docker Hub and GitHub Container Registry.
Docker Hub variables:
export DOCKER_USERNAME=<your_docker_username>
export DOCKER_PASSWORD=<your_docker_password_or_token>GitHub Container Registry variables:
export GHCR_TOKEN=<your_github_token>--container: Name of the container image (required)--registry: Which registry to prune (ghcr,dockerhub,all)--verbose: Enable verbose output--dry-run: Show what would be deleted without actually deleting
Pruning Strategies (mutually exclusive):
--prune-untagged-age DAYS: Delete untagged images older than DAYS--prune-all-untagged: Delete all untagged images--keep-latest COUNT: Keep only the latest COUNT images
# Prune untagged images older than 7 days from both registries
python main.py --container magika --registry all --prune-untagged-age 7 --verbose
# Keep only the latest 5 images in GHCR (delete everything else)
python main.py --container magika --registry ghcr --keep-latest 5 --verbose
# Dry run: see what would be deleted from Docker Hub
python main.py --container magika --registry dockerhub --prune-all-untagged --dry-run --verbosepython test_runner.py # Run all testsFor comprehensive testing documentation, see
tests/README.md.