
Container Diet
Slim down your Docker images with AI-powered sass. 🐳💅
114 followers
Slim down your Docker images with AI-powered sass. 🐳💅
114 followers
Stop shipping bloated containers! Container Diet is a CLI tool that analyzes your Docker images and Dockerfiles to provide actionable, context-aware optimization advice. It uses AI to detect unnecessary packages, security risks, and bad practices—all while delivering feedback in a "sassy dietician" persona that makes optimization fun.



Container Diet
Container Diet
Hey hunters! 👋
Since the initial launch of Container Diet, the CLI has gone through a serious evolution. Here's everything that shipped since v0.1.0:
🛠️ --auto-fix — The killer feature
Stop reading advice and start applying it. Pass --auto-fix and the Container Dietician writes you a complete, optimized Dockerfile.diet on the spot — works even without a source Dockerfile by reverse-engineering your image layers.
container-diet analyze --dockerfile Dockerfile --auto-fix
# → Writes Dockerfile.diet with all fixes applied
🌐 --remote & --pull-missing
Analyze any image, anywhere. --remote pulls straight from a registry without needing a local copy. --pull-missing keeps local-first behavior but auto-pulls if the image isn't found locally.
container-diet analyze python:3.11-slim --remote
container-diet analyze busybox --pull-missing
🎨 Colorful, structured CLI output
The terminal output was completely redesigned — Docker-brand cyan/magenta/green color coding, emoji status indicators (✖, ✓, ⚠), neon section headers, and a tabular layer-by-layer size breakdown. --help now renders a fully styled, structured template instead of the default Cobra output.
🧠 Smarter AI analysis (v0.1.1 → v0.3.0)
- Added package manager cache advice — the AI now specifically calls out un-cleared apt, pip, and npm caches that silently bloat your layers
- Switched to a structured JSON response (AnalysisResponse) so advice and auto-fix content are cleanly separated and reliably parsed
- AI client hardened with a 90-second timeout, context-based request cancellation, and proper type-safe API response parsing
⚙️ Analyzer & internals refactored
Removed the old CheckDaemon pre-flight check, collapsed layer metadata collection into a single efficient pass, and wired in the pullMissing parameter for clean remote-fallback control — no dead code, no unnecessary os/exec calls.
Full CLI feature surface:
- 🧠 GPT-4o Analysis — context-aware roasts _and_ actionable optimization tips
- 🛠️ --auto-fix — generates a ready-to-use Dockerfile.diet with all fixes applied
- 🌐 --remote — analyze any public registry image without a local daemon copy
- 🔄 --pull-missing — local-first with automatic remote fallback
- 🛡️ Security Audits — root users, exposed secrets, chmod 777 caught and called out
- 🎨 Beautiful CLI output — Docker-brand colors, tabular layer analysis, neon section headers
- 📄 --dockerfile — pass your Dockerfile for richer, more targeted AI advice
- 🤖 --model — swap in any OpenAI model (defaults to gpt-4o)
The biggest thing I shipped since launch is --auto-fix. I got tired of reading optimization advice and then having to manually apply it — so I made the AI just write the fixed Dockerfile for you. It reverse-engineers your image layers if you don't even have a Dockerfile handy. The CLI output also got a full makeover with colors, emojis, and structured sections so it actually feels good to use in the terminal. Would love to hear what you think — and what you'd want next (TUI mode? CI integration? Drop it in the comments)!"
Links:
- 🔗 Repo: https://github.com/k1lgor/container-diet
- 🌐 Web: https://k1lgor.github.io/container-diet/
- 📦 Install: go install github.com/k1lgor/container-diet/cmd/cli@latest
Bookmarkjar ®
Container Diet
@nikuscs The diff is that you can run it locally, no need to copy/paste the whole Dockerfile content. Can analyze your local images as well, layer by layer and main focus is layers, unnecessary packages or build tools, security risks, and multi-stage build suggestions.
@k1lgor Love this, making Docker optimisation fun is such a clever angle.
Curious: does Container Diet just analyze the final image, or can it actually suggest alternative base images / multi-stage setups too? That’s where most people’s “container calories” come from.
Container Diet
@fernando_scharnick Thanks! I figured if I have to deal with bloat, I might as well make it entertaining. 🏋️♂️
To answer your question: Yes, absolutely.
The 'Dietician' goes after those heavy calories first. Since it analyzes your Dockerfile (if provided) alongside the image layers, it specifically looks for:
Base Image Swaps: It will catch if you're using a heavy base (like ubuntu:latest or standard python) and suggest specific slim, alpine, alternatives compatible with your stack.
Multi-Stage Architecture: If it sees build artifacts (compilers, headers, source code) lingering in the final image, it will suggest refactoring into a multi-stage build to leave that weight behind.
@k1lgor Haha love it, if we’re stuck dealing with container calories, might as well burn a few laughs along the way 😄
And that’s super helpful context. The base-image swaps + multi-stage refactor tips are exactly the kind of “why didn’t I catch that?” moments that make a tool like this worth running on every build. Excited to see how the Dietician evolves!
Container Diet
@fernando_scharnick I really like your point about running it on 'every build.' I’m actually exploring a CI/CD integration next, so the Dietician can automatically block a PR if it tries to sneak in too many calories. Thanks for the encouragement! 🐳
Can we not use other AIs for the same?
Can Container Diet generate images?
Container Diet
@premansh_tomar Good questions!
Vs. Generic AIs: You technically can, but you'd be working blind. Standard AIs only see the text you paste. Container Diet connects to your local Docker daemon to inspect the actual built layers. It feeds the AI real data—like specific file sizes, permissions, and hidden cache folders—so the advice is based on reality, not just the Dockerfile syntax.
Generating Images: It doesn't generate the image itself (you still run docker build). Think of it as a critic rather than a creator. It analyzes the image you already built, identifies the bloat, and gives you the code changes to shrink it. 📉
Swytchcode
Nice, Was looking for something like that. Will try this.
Container Diet
@chilarai Awesome! Let me know how much weight (MBs or GBs) your containers manage to lose. 📉
I'd love to hear your feedback once you've given it a spin—especially if the AI dietician gets a little too sassy with your code. Happy optimizing! 🐳
Makers Page
lol @ "why is this 2GB?" felt. The sassy dietician vibe might actually make me fix stuff instead of shrugging. Love that it's local-only. Curious if it groks multi-stage builds and package manager caches (pip/npm). Tossing it at a chunky image later.
Container Diet
@alexcloudstar Haha, glad the vibe resonates! Yes! The AI specifically analyzes your build stages. If you aren't using multi-stage builds (or using them inefficiently), the Dietician will definitely call you out for carrying 'dead weight' like build tools in your final image. But I might have missed adding the caching to the Dietician focus.
Can't wait to see what it says about your chunky image—hope it survives the roast! 🍗🐳