Skip to content

DobryySoul/dockr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

22 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CI & Release

Dockr 🐳

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.

Features

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

Installation

Linux / macOS (Quick Install):

curl -sSfL https://raw.githubusercontent.com/DobryySoul/dockr/main/scripts/install.sh | bash

Using Go:

go install github.com/DobryySoul/dockr@latest

Alternatively, 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.go

Usage

Simply run the utility from the command line:

dockr [flags]

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

Uninstallation

If you used the installation script (install.sh), remove the binary:

sudo rm /usr/local/bin/dockr

If you installed it via go install, remove it from your Go bin path:

rm $(go env GOPATH)/bin/dockr

Testing

The 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 ./...

Project Structure

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

Dependencies

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.

About

🐳 A smart and safe CLI tool written in Go for cleaning up unused Docker resources (images, containers, volumes, networks).

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors