Skip to content

coolhead/dockerfile-doctor

Repository files navigation

🩺 Dockerfile Doctor

Paste your Dockerfile → get a smaller, safer, production-ready version in seconds.

Dockerfile Doctor is an AI-powered optimization tool that automatically rewrites Dockerfiles using best practices. It helps you reduce image size, improve security, fix anti-patterns, and instantly get a clean, optimized Dockerfile.

Built using Kiro, Streamlit, and a modular optimization engine.


Try It Locally

streamlit run frontend/app.py


Key Features

Intelligent Dockerfile Analysis

Understands your Dockerfile line-by-line and detects:

  • Redundant layers

  • Inefficient RUN commands

  • Missing security hardening

  • MLOps-specific stack (PyTorch, TensorFlow, Transformers, vLLM, etc.)

  • Build-cache breakers

  • Potentially unsafe instructions

⚙️ Automatic Optimization

  • Dockerfile Doctor rewrites the file using best-practice patterns:

  • Merge and compact RUN layers

  • Add non-root user and permissions

  • Add recommended packages

  • Remove unused instructions

  • Auto-detect ML stack and adjust base image

  • Improve caching and build reproducibility

🛡️ Zero-Trust Security Score

Each optimized image receives a 0–100 security score based on:

  • Root vs non-root user

  • Number of unsafe instructions

  • Presence of leaked secrets

  • Common misconfigurations

  • Basic CVE-related checks

Full Diff View

You can see exactly what changed:

--- Original Dockerfile
+++ Optimized Dockerfile
- CMD ["python", "app.py"]
+ RUN useradd -m appuser
+ USER appuser

This makes it easy to review and commit changes safely.

⬇️ One-Click Download

A clean Dockerfile.optimized is generated automatically — ready to push into your repo.

🧩 Home Screen

UI before optimization

⚡ Optimization Results

Optimization results

Architecture Overview

dockerfile-doctor/
├── app/
│   ├── analyzer.py        # Dockerfile parser
│   ├── optimizer.py       # Rules engine that rewrites Dockerfile
│   ├── security.py        # Security scoring engine
│   ├── mlops_mode.py      # ML stack detector
│   ├── diff_utils.py      # Diff builder
│   └── models.py          # Pydantic models
├── frontend/
│   └── app.py             # Streamlit UI
└── tests/                 # Unit tests

The backend is modular — each component handles a specific transformation:

  • Analyzer → tokenizes and normalizes the Dockerfile

  • Optimizer → applies 12+ rewrite rules

  • Security Engine → computes the zero-trust score

  • MLOps Detector → adjusts optimizations for ML workloads

  • Diff Builder → generates unified diffs for UI display

Running Tests

python -m pytest -q

All core components include unit tests to ensure rule reliability.

Local Development

git clone https://github.com/coolhead/dockerfile-doctor.git
cd dockerfile-doctor
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
streamlit run frontend/app.py

Roadmap

  • Before/After image size prediction
  • BuildKit-powered caching heatmap
  • GitHub Action: Auto-PR with optimized Dockerfile
  • Trivy-powered CVE scan
  • CLI tool (dockerfile-doctor --fix Dockerfile)
  • VSCode extension

🤝 Contributing

Contributions are welcome! Feel free to open issues or propose features.

📜 License

MIT License © 2025 Raghavendra S

⭐ Acknowledgements

Built using:

Kiro — AI automation engine

Streamlit — UI framework

Python — core backend

🔗 Links

GitHub Repo: https://github.com/coolhead/dockerfile-doctor

Challenge Submission: https://builder.aws.com/content/361lkwNCmn71f4mdS3HFm4odNzP/building-dockerfile-doctor-an-ai-powered-dockerfile-optimizer-with-kiro-and-streamlit

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages