Dockr is a smart CLI utility for safely cleaning up unused Docker resources (images, containers, volumes, and networks). The tool is written in Go and provides a user-friendly command-line interface to keep your host machine clean.
- Smart Analysis: Finds orphaned images, exited containers, and unused volumes/networks.
- Safe Deletion: Supports interactive mode (
-i) to prompt for confirmation before cleaning up. - Exceptions: Ability to protect specific images from deletion by their tags (
-e). - Dry-Run Mode: Allows you to view a report of what would be deleted without actually making changes to the system (
-d). - Informative: Colored and structured table output with a calculation of freed disk space.
Linux / macOS (Quick Install):
curl -sSfL https://raw.githubusercontent.com/DobryySoul/dockr/main/scripts/install.sh | bashUsing Go:
go install github.com/DobryySoul/dockr@latestAlternatively, you can build the project yourself if you have Go installed:
# Clone the repository
git clone https://github.com/DobryySoul/dockr.git
cd dockr
# Build the project
go build -o dockr main.goSimply run the utility from the command line:
dockr [flags]-d, --dry-runβ Simulation mode: prints information about resources that would be deleted, without actually removing them.-i, --interactiveβ Interactive mode: asks for user confirmation before deleting resources.-e, --exclude-tagsβ Exclude specific image tags from deletion (can be specified multiple times, e.g.,-e latest -e prod).-a, --allβ Delete ALL unused resources (including potentially important ones).-v, --versionβ Show the current application version.
If you used the installation script (install.sh), remove the binary:
sudo rm /usr/local/bin/dockrIf you installed it via go install, remove it from your Go bin path:
rm $(go env GOPATH)/bin/dockrThe project is covered by unit tests to verify the correctness of the business logic (rules for determining if resources are "unused"). To run the tests, execute the following command:
go test -v ./...The codebase is built with clean architecture principles and standard Go project conventions in mind. Purpose of main directories:
.
βββ cmd/ # CLI commands (based on Cobra). Initialization and flag setup
β βββ root.go # Root command 'dockr'
βββ internal/ # Internal application business logic (cannot be imported externally)
β βββ analyzer/ # Analysis logic: determining if a resource is used or can be deleted
β βββ cleaner/ # Methods for actually deleting objects from Docker
β βββ docker/ # Docker SDK wrapper, methods for interacting with Docker Daemon
β βββ domain/ # Core data structures and models (e.g., UnusedResources)
βββ pkg/ # Public packages (potentially reusable)
β βββ formatter/ # Output formatting utilities (tables, colored text, calculations)
βββ scripts/ # Helper bash scripts (e.g., install.sh)
βββ Makefile # Automation commands (build, test, linters, etc.)
βββ main.go # Application entry point
The project relies on reliable open-source solutions:
- Cobra β A framework for creating powerful CLI applications.
- Docker Engine API / moby β The official Go client for interacting with the Docker API.
- fatih/color β A handy package for formatting and printing colored text to the console.