Skip to content

Slim down your Docker images with the power of AI. Container Diet analyzes your images and Dockerfiles to provide actionable, context-aware optimization advice.

License

Notifications You must be signed in to change notification settings

k1lgor/container-diet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

17 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿณ Container Diet CLI

Slim down your Docker images with the power of AI.

Container Diet is a futuristic, AI-powered CLI tool that analyzes your Docker images and Dockerfiles to provide actionable, "sassy but helpful" optimization advice. It helps you reduce image size, improve security, and follow best practices.

Container Diet Logo

โœจ Features

  • ๐Ÿง  AI-Driven Analysis: Uses OpenAI (GPT-4o) to provide human-level, context-aware optimization tips.
  • ๐Ÿณ Docker-Themed UI: Beautiful CLI output with Docker-brand colors and nautical icons.
  • ๐Ÿ  Local First: Checks your local Docker daemon first to avoid unnecessary remote pulls.
  • ๐Ÿ›ก๏ธ Security Focused: Detects root user violations, exposed secrets, and unnecessary packages.
  • ๐ŸŽญ "Container Dietician" Persona: Enjoy entertaining, roast-style feedback that keeps optimization fun.

๐Ÿš€ Installation

Prerequisites

  • Go 1.21+
  • Docker or Podman running locally
  • OpenAI API Key

Install via Go

go install github.com/k1lgor/container-diet/cmd/cli@latest

Build from Source

git clone https://github.com/k1lgor/container-diet.git
cd container-diet
go mod tidy
go build -o container-diet cmd/cli/main.go

โš™๏ธ Configuration

You must set your OpenAI API key before running the tool:

Linux/macOS:

export OPENAI_API_KEY="sk-..."

Windows (PowerShell):

$env:OPENAI_API_KEY="sk-..."

๐Ÿ“– Usage

Analyze a Local Image

container-diet analyze my-app:latest

Analyze with Dockerfile Context

Providing the Dockerfile gives the AI more context for better suggestions.

./container-diet analyze my-app:latest --dockerfile Dockerfile

Analyze a Remote Image

By default, the tool only looks locally. Use --remote to pull from a registry.

./container-diet analyze python:3.9-slim --remote

Full Help

./container-diet analyze --help

๐ŸŽฎ Demo Output

Here is what happens when you feed the "Nightmare Monolith" Dockerfile to the Container Dietician:

Command:

./container-diet analyze --dockerfile samples/Dockerfile.nightmare

Output:

Reading Dockerfile: samples/Dockerfile.nightmare...

๐Ÿณ [AI ANALYSIS COMPLETE]
Asking the Container Dietician for insights... ๐Ÿšข

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! Letโ€™s roll up our sleeves and clean this galactic
mess. ๐Ÿš€

---

โš  WARNING: Version Drift Alert!
You've got a "fluffy" problem right at the start, darling! 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 just about everything but the kitchen sink, are we? This is the definition of bloat,
my dear. ๐Ÿ˜

โœ“ SUGGESTION: Install only what's necessary for your app. Consider slimming it down by ditching
`openjdk-11-jdk`, `build-essential`, `cmake`, and `gdb` unless you truly need them. Otherwise,
you're just hoarding bytes.

---

โš  WARNING: Hazardous Permissions Play!
777 permissions? I hope youโ€™re wearing a hard hat! This is a security risk as wide as a black
hole. ๐ŸŒŒ

โœ“ SUGGESTION: Use more restrictive permissions. Typically, `chmod -R 755` or `chmod -R 644`,
depending on whatโ€™s needed for executing.

---

โš  WARNING: Root Cabal Alert!
Running SSH as root with root login permitted? You might as well hand over the keys to the
universe. ๐Ÿ”‘

โœ“ SUGGESTION: Disable root login and use a non-root user. Also, ask yourselfโ€”do you really need
SSH in a container? Usually, it's a sign you need to rethink your strategy.

---

Oh, darling, letโ€™s trim down that bloated ship before it swallows a sun. Your future workloads
will thank you for the speed and safety tunes! Now, get to work, ๐Ÿ› ๏ธ and remember: less is always
more. ๐Ÿณโœจ

๐Ÿ—๏ธ Project Structure

  • cmd/cli: Main entry point for the CLI.
  • internal/cli: CLI command definitions and logic.
  • internal/ai: OpenAI client integration.
  • internal/analyzer: Core image analysis logic (layers, size, config).
  • samples/: Collection of Dockerfiles for testing (Light to Nightmare). See demo outputs.

๐Ÿ“„ License

MIT

About

Slim down your Docker images with the power of AI. Container Diet analyzes your images and Dockerfiles to provide actionable, context-aware optimization advice.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published