This content originally appeared on DEV Community and was authored by Damilare Ajakaiye
Picture this: I'm mid-project, juggling three Docker containers, testing a new microservice architecture, when suddenly… my laptop screams at me: "No disk space left!"
I check Docker. 12GB of images I don't remember downloading, stopped containers from experiments, dangling volumes… and yeah, build caches from weeks ago. My usual go-to, docker system prune, felt like defusing a bomb blindfolded. One wrong flag and I could lose hours of work.
I realized I needed a smarter, safer approach. Enter Dockerclean — my little Go CLI project that now keeps my Docker environment lean, predictable, and pain-free.
The Problem
Docker is amazing, but it hoards disk space like a dragon. Unused images, stopped containers, orphaned volumes, and leftover build cache silently pile up, slowing down builds and filling your storage.
Developers often run docker system prune or forget about it altogether, risking data loss or wasting hours cleaning manually. I wanted a solution that:
- Shows exactly what's using disk space
- Lets me prune safely or fully, depending on the risk I'm willing to take
- Is easy to install and run anywhere
How I Built It
I went with Go because it's fast, statically typed, and perfect for CLI tools. Here's the breakdown:
Analyzer (internal/analyzer)
- Connects to Docker using the Go SDK
- Scans images, containers, volumes, and build cache
- Reports disk usage in a human-friendly, color-coded format
Cleaner (internal/cleaner)
- Wraps Docker prune commands safely
-
--safemode removes only stopped or dangling resources - Full prune removes everything, but always asks for confirmation
CLI (cmd/)
Built with Cobra for robust command parsing. Uses fatih/color for instant visual cues — green for safe, yellow for warnings, red for critical.
Commands are intuitive:
# Analyze your Docker environment
dockerclean analyze
# Safe prune
dockerclean prune --safe
# Full prune (confirmation required)
dockerclean prune
Testing
Wrote unit tests for analyzer and cleaner packages to ensure safe operations. Coverage is 100% for the core logic, so nothing accidentally nukes my running containers.
The Result
Now, instead of wondering "What's eating my disk?", I just run:
dockerclean analyze
…and see a clean summary of total usage, per-resource breakdown, and a safety assessment.
Need to reclaim space?
dockerclean prune --safe
or, if I'm feeling bold:
dockerclean prune
Everything's logged, color-coded, and predictable. No more surprises.
Lessons Learned
- Visibility first — never prune blindly
- Go + Cobra + Docker SDK = a dream team for CLI tools
- Tests are non-negotiable — safe operations are useless without confidence in your code
- Color-coded terminal output makes a surprisingly big difference when scanning usage stats
Dockerclean started as a personal tool, but now I hope it helps others who are tired of Docker eating their storage silently.
Try it yourself: github.com/pozadkey/dockerclean
This content originally appeared on DEV Community and was authored by Damilare Ajakaiye
Damilare Ajakaiye | Sciencx (2025-11-23T02:38:16+00:00) Dockerclean — How I Learned to Stop Worrying and Love Safe Docker Cleanup. Retrieved from https://www.scien.cx/2025/11/23/dockerclean-how-i-learned-to-stop-worrying-and-love-safe-docker-cleanup/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.