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.
streamlit run frontend/app.py
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
-
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
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
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.
A clean Dockerfile.optimized is generated automatically — ready to push into your repo.
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
python -m pytest -q
All core components include unit tests to ensure rule reliability.
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
- 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
Contributions are welcome! Feel free to open issues or propose features.
MIT License © 2025 Raghavendra S
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

