A Docker environment cleanup and optimization tool written in Bash. This script analyzes your Docker disk usage, prunes unused containers, images, networks, volumes, and build caches, and provides a detailed report of the reclaimed space.
- Usage Analysis: Calculates Docker disk usage before and after cleanup using standard tools.
- Full Pruning: Cleans stopped containers, all images (not just dangling), unused networks, and all build caches.
- Volume Cleanup: Removes all unused volumes to reclaim maximum space.
- Zero Dependencies: Optimized for portability; works on Arch Linux, Debian, Ubuntu, etc.
- Terminal Portability: Uses
tputfor robust terminal styling across Linux and macOS. - Hard Reset Mode: Can stop all running containers before purging with the
--forceflag. - Interactive Support: Works seamlessly when piped from
curlby using/dev/tty.
bash(version 4+)docker(installed and running)
Ensure your user has permissions to run Docker commands without sudo, or run the script with appropriate privileges.
Choose one of the following methods:
Downloads and executes the script. Use the following syntax to pass arguments:
Standard interactive cleanup:
curl -fsSL https://raw.githubusercontent.com/sam0rr/docker_purge/main/docker_purge.sh | bashWith arguments:
curl -fsSL https://raw.githubusercontent.com/sam0rr/docker_purge/main/docker_purge.sh | bash -s -- --force --no-confirm- Download to
/usr/local/bin:
sudo curl -fsSL \
https://raw.githubusercontent.com/sam0rr/docker_purge/main/docker_purge.sh \
-o /usr/local/bin/docker_purge- Make executable:
sudo chmod +x /usr/local/bin/docker_purge- Run it directly:
docker_purge- validate_requirements: Ensures
dockeris available and the daemon is reachable. - get_docker_usage: Uses
docker system dfandawkto calculate total byte usage. - confirm_purge: Provides a warning and asks for user confirmation.
- perform_cleanup:
- Stops all running containers if
--forceis used. - Sequentially executes
builder prune,container prune,image prune,volume prune, and a finalsystem prune.
- Stops all running containers if
- display_summary: Compares pre and post usage, formatting the results into a clean, colored report.
You can view the help message by running docker_purge --help:
--no-confirm: Skip interactive prompts (useful for automation).--force: Stop all currently running containers before starting the cleanup.
MIT License © 2026 Samorr