Introduction
Dockerfiles are everywhere — from microservices to ML pipelines to serverless workloads masquerading as containers.
But most Dockerfiles in the wild? Let’s just say they're… not healthy.
Layers duplicated. Security hardening missing. RUN commands exploding cache.
No non-root users. No structure. No reproducibility. No love.
So I built Dockerfile Doctor — an AI-powered tool that automatically rewrites Dockerfiles using industry best practices, helping developers ship smaller, safer, and production-ready containers in seconds.
This project is built using Kiro + Streamlit, with a modular rules engine powering the optimization.
Why I Built This
Every week I work with DevOps, MLOps, and GenAI systems.
No matter how advanced the stack is, I see the same problems:
- Missing security hardening
- ML images bloated with unnecessary dependencies
I wanted a tool that:
✔ Reads your Dockerfile
✔ Understands it line by line
✔ Identifies anti-patterns
✔ Rewrites the entire file
✔ Gives you a diff
✔ Scores it with a Zero-Trust model
…in one click.
How I Built It (Architecture)
dockerfile-doctor/
├── dockerdoctor/
│ ├── analyzer.py # Tokenizer + line parser
│ ├── optimizer.py # Best-practice rules engine
│ ├── security.py # Zero-Trust scoring system
│ ├── mlops_mode.py # MLOps stack detector (Torch, TF, HF, vLLM)
│ ├── diff_utils.py # Unified diff generator
│ └── models.py # Pydantic models
├── frontend/
│ └── app.py # Streamlit UI
└── tests/
The Engine Behind It
The rules engine performs:
- Base-image recommendations
- MLOps stack auto-detection
- Instruction normalization
It returns:
- Optimized Dockerfile content
- A Zero-Trust security score
The UI renders everything cleanly using Streamlit.
Features:
AI-Powered Optimization
- Convert CMD to JSON array format
- Add non-root user automatically
Zero-Trust Security Score
A 0–100 score based on:
MLOps Smart Mode
Detects frameworks like:
- vLLM / FastAPI ML workloads
…and applies ML-specific optimizations.
What I Learned While Building This
- How to design a modular rules engine
- How to build a UI/UX that feels instant and developer-friendly
- How to integrate security checks into DevOps tooling
- How to score container hardening effectively
- How to use Kiro for fast backend iteration
This project gave me clarity on how small rewrites drastically improve Dockerfile hygiene.
Roadmap
Coming soon:
- CLI tool:
dockerfile-doctor --fix Dockerfile
- GitHub Action: Auto-PR with optimized Dockerfile
🔗 Source Code
(Repo will be made public after publishing this article.)
Final Thoughts
Dockerfile Doctor started as a weekend experiment…
and quickly became a tool I now use every single day in my DevOps and MLOps workflows.
If this helps even one developer ship cleaner images, the project was worth it.
If it helps thousands — that’s the dream.
Let's build clean. Let's build secure. Let's build fast.
Loading article