Skip to content

sam0rr/docker_purge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 

Repository files navigation

Docker Purge

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.


Features

  • 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 tput for robust terminal styling across Linux and macOS.
  • Hard Reset Mode: Can stop all running containers before purging with the --force flag.
  • Interactive Support: Works seamlessly when piped from curl by using /dev/tty.

Prerequisites

  • 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.


Installation

Choose one of the following methods:

1. One‑line execution (curl)

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 | bash

With arguments:

curl -fsSL https://raw.githubusercontent.com/sam0rr/docker_purge/main/docker_purge.sh | bash -s -- --force --no-confirm

2. Install as a system command

  1. 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
  1. Make executable:
sudo chmod +x /usr/local/bin/docker_purge
  1. Run it directly:
docker_purge

How it works

  1. validate_requirements: Ensures docker is available and the daemon is reachable.
  2. get_docker_usage: Uses docker system df and awk to calculate total byte usage.
  3. confirm_purge: Provides a warning and asks for user confirmation.
  4. perform_cleanup:
    • Stops all running containers if --force is used.
    • Sequentially executes builder prune, container prune, image prune, volume prune, and a final system prune.
  5. display_summary: Compares pre and post usage, formatting the results into a clean, colored report.

CLI Usage

You can view the help message by running docker_purge --help:


Arguments

  • --no-confirm: Skip interactive prompts (useful for automation).
  • --force: Stop all currently running containers before starting the cleanup.

License

MIT License © 2026 Samorr


About

Docker purge utility to save disk space

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages