AI-powered Docker image optimization — because your containers could use a diet.
Container Diet analyzes your Docker images and Dockerfiles, then serves up sassy, actionable advice backed by your choice of 12+ AI providers. Catch bloated layers, security holes, and missing best practices before they reach production. Works as a CLI, in CI/CD, or as an MCP tool inside your AI editor.
# 1. Install
go install github.com/k1lgor/container-diet/cmd/cli@latest
# 2. Configure your AI provider
container-diet init-config
# → edit ~/.config/container-diet/config.yaml
# → uncomment your provider, paste your API key
# 3. Analyze
container-diet analyze --dockerfile Dockerfile --auto-fixThat's it. You'll get a roast of your Dockerfile, actionable fixes, and a Dockerfile.diet with the optimizations applied.
Container Diet talks to any of these — bring the key you already have, or run locally for free.
| Provider | Config Key | API Key Env Var |
|---|---|---|
| OpenAI | openai |
OPENAI_API_KEY |
| Anthropic (native) | anthropic |
ANTHROPIC_API_KEY |
| OpenRouter | openrouter |
OPENROUTER_API_KEY |
| Groq | groq |
GROQ_API_KEY |
| DeepSeek | deepseek |
DEEPSEEK_API_KEY |
| Mistral | mistral |
MISTRAL_API_KEY |
| xAI (Grok) | xai |
XAI_API_KEY |
| Ollama (local, free) | ollama |
none needed |
| Perplexity | perplexity |
PERPLEXITY_API_KEY |
| Moonshot | moonshot |
MOONSHOT_API_KEY |
| Hugging Face | huggingface |
HF_API_TOKEN |
| Custom endpoint | custom |
CUSTOM_API_KEY |
Switch providers with --provider or set default_provider in your config.
Container Diet ships as an MCP (Model Context Protocol) server so AI agents can analyze containers directly from your editor.
Supported clients: Claude Desktop · Cursor · Claude Code · Codex · any MCP-compatible agent
Add to your MCP client config:
{
"mcpServers": {
"container-diet": {
"command": "container-diet",
"args": ["mcp", "server"]
}
}
}No API keys in the MCP config — the server reads them from ~/.config/container-diet/config.yaml.
Tools exposed to AI agents:
| Tool | Description |
|---|---|
analyze_dockerfile |
AI analysis with optional auto-fix generation |
analyze_image |
Layer breakdown + AI optimization advice |
get_optimization_advice |
General container advice from free-form context |
get_image_summary |
Quick metrics without burning AI tokens |
Full setup guide: container-diet mcp init
container-diet analyze --dockerfile Dockerfilecontainer-diet analyze --dockerfile Dockerfile --auto-fix
# Writes Dockerfile.diet with optimizations applied# Local daemon
container-diet analyze nginx:latest
# Pull from registry
container-diet analyze python:3.12-slim --remote
# Auto-pull if missing locally
container-diet analyze busybox --pull-missingcontainer-diet analyze --dockerfile Dockerfile --format json{
"advice": "⚠ WARNING: Root user detected...\n✓ SUGGESTION: Use non-root user...",
"fix": "FROM nginx:alpine\nUSER nginx\n..."
}container-diet analyze --dockerfile Dockerfile --provider anthropic --model claude-sonnet-4-6Running the "Nightmare Monolith" Dockerfile through Container Diet:
📄 Reading Dockerfile: samples/Dockerfile.nightmare...
🤖 [AI ANALYSIS]
🚢 Asking the Container Dietician for insights using openrouter (openai/gpt-4o-mini)
================================================================
Oh, honey, what do we have here? A "Monolith Monster" Dockerfile that's
about to sink your ship with its fatty layers and spicy security risks! 🚀
---
⚠ WARNING: Version Drift Alert!
Using `ubuntu:latest` means you're playing roulette with your build
environment. 🎰
✓ SUGGESTION: Pin your base image to a specific version like
`ubuntu:22.04` to keep things predictable.
---
⚠ WARNING: Apt-get Avalanche!
Installing everything but the kitchen sink? This is the definition of
bloat, my dear. 🐘
✓ SUGGESTION: Ditch `openjdk-11-jdk`, `build-essential`, `cmake`, and
`gdb` unless you truly need them.
---
⚠ WARNING: 777 permissions? Root SSH? Root login permitted?
You might as well hand over the keys to the universe. 🔑
✓ SUGGESTION: Use non-root user, restrictive permissions. And ask
yourself — do you really need SSH in a container?
---
Oh, darling, trim that bloated ship before it swallows a sun! 🐳✨
Config file locations (searched in order, later overrides earlier):
| Priority | Path | Scope |
|---|---|---|
| 1 (highest) | --config <path> flag |
Per-command |
| 2 | .container-diet/config.yaml |
Per-project |
| 3 (lowest) | ~/.config/container-diet/config.yaml |
Global |
Minimal config example:
default_provider: "openrouter"
providers:
openrouter:
api_key: "${OPENROUTER_API_KEY}" # or paste the key directly
base_url: "https://openrouter.ai/api/v1"
default_model: "openai/gpt-4o-mini"
timeout_seconds: 90
analysis:
max_tokens: 4096
ui:
theme: "docker"
show_emojis: trueGenerate the full example with all providers: container-diet init-config
Pro-tip: use --local for project-specific config, --force to overwrite.
cmd/cli/main.go # Entry point
internal/
├── ai/ # Provider interface + implementations
│ ├── provider.go # Interface, prompt builders, retry logic
│ ├── anthropic.go # Anthropic native API
│ └── openai_compatible.go # OpenAI, OpenRouter, Ollama, Groq, etc.
├── analyzer/ # Docker image layer inspection
├── cli/ # Cobra commands (analyze, init-config, mcp)
├── config/ # YAML config loading with env var expansion
├── mcp/ # MCP server (stdio transport, 4 tools)
├── samples/ # Test Dockerfiles (light → nightmare)
└── web/ # Landing page (React + Three.js)
MIT © 2026 Container Diet
Built with 🐳 and a touch of sass.
