Free and open-source Dockerfile optimizer that helps you build smaller, faster, and more secure Docker images.
- π Intelligent Analysis - AI-powered analysis with Gemini for detailed Dockerfile optimization
- π¦ Size Reduction - Reduce image size by up to 70% with optimized base images and multi-stage builds
- π Security Fixes - Automatically detect and fix security issues (non-root user, pinned versions, etc.)
- β‘ Performance - Optimize layer caching and reduce build time by up to 42%
- π Detailed Reports - Get comprehensive reports with before/after comparisons
- π Web Interface - Beautiful web UI for instant Dockerfile optimization
- π οΈ CLI Tool - Command-line tool for CI/CD integration
- π Multiple Formats - Support for text, JSON, Markdown, and SARIF output formats
- 𧬠Image Inspector - Deep dive into Docker image layers (like Dive)
- π Build Replay - Visual timeline of Docker build process with cache analysis
- π§ Layer AI - AI-powered layer behavior analysis and optimization suggestions
- βοΈ Config Wizard - Interactive wizard for Docker configuration optimization
- π Secret Detection - Automatically detect secrets and sensitive data
- π Layer DNA Compare - Visual comparison of image layer composition
Visit the web interface for instant optimization:
- Paste your Dockerfile
- Click "Optimize"
- Get optimized Dockerfile with detailed analysis
git clone https://github.com/duongtech/dockeropt.git
cd dockeropt
npm install
npm run build
npm linknpx -y dockeropt lint Dockerfile
npx -y dockeropt fix Dockerfilenpm install -g dockeropt# Lint Dockerfile for issues
dockeropt lint Dockerfile
# Optimize and generate fixed Dockerfile
dockeropt fix Dockerfile -o out
# Run in CI mode (fails on high severity issues)
dockeropt ci Dockerfile --fail-on high
# Explain Dockerfile structure and suggestions
dockeropt explain Dockerfiledockeropt lint <dockerfile> [options]
Options:
-f, --format <format> Output format: text, json, sarif (default: text)
--context <path> Path to build context directory
--package-manager <pm> Package manager: npm, pnpm, yarn, apt, apk, pip, poetry, go, cargodockeropt fix <dockerfile> [options]
Options:
-o, --output <path> Output directory (default: out)
-f, --format <format> Report format: text, markdown, json (default: markdown)
--context <path> Path to build context directory
--package-manager <pm> Package manager typedockeropt ci <dockerfile> [options]
Options:
--format <format> Output format: sarif, json (default: sarif)
--out <file> Output file path (default: results.sarif)
--fail-on <severity> Fail on severity: high, medium, low (default: high)
--context <path> Path to build context directoryBefore (Unoptimized):
FROM node:18
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build
RUN apt-get update
RUN apt-get install -y curl wget
EXPOSE 3000
CMD ["npm", "start"]After (Optimized):
FROM node:18-alpine@sha256:a6385524b09b9de27e332b22e90fb7a70e3adf1a41a54edd0c8e6e597f4e9aaf AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev && npm cache clean --force
COPY . .
RUN npm run build
FROM node:18-alpine@sha256:a6385524b09b9de27e332b22e90fb7a70e3adf1a41a54edd0c8e6e597f4e9aaf
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
USER node
CMD ["node", "dist/index.js"]Results:
- Size reduction: ~135 MB
- Layer reduction: 3 layers
- Build time improvement: ~42%
- Security: Non-root user added
- Cache efficiency: Improved
DockerOpt applies 11+ optimization rules:
- β Multi-stage builds - Separate build and runtime stages
- β Layer caching - Optimize COPY order for better cache hits
- β Base image optimization - Use Alpine, slim, or distroless variants
- β Pin digest - Pin base images with SHA256 for reproducible builds
- β Non-root user - Run containers as non-root for security
- β Clean package managers - Remove package manager cache
- β Combine RUN commands - Reduce number of layers
- β Use .dockerignore - Exclude unnecessary files
- β
Pin versions - Use specific versions instead of
latest - β Minimize layers - Combine related operations
- β Security scanning - Detect security vulnerabilities
DockerOpt has optimized examples for:
- Node.js - npm, yarn, pnpm
- Python - pip, poetry
- Go - Go modules
- Java - Maven, Gradle
- Rust - Cargo
- PHP - Composer
- Ruby - Bundler
- And more...
The web interface provides:
- π Live Editor - Monaco editor with syntax highlighting
- π Visual Metrics - Size, layer, and build time comparisons
- π Side-by-Side Diff - Before/After comparison
- π¨ Beautiful UI - Modern, responsive design
- π GitHub Integration - Fetch Dockerfiles directly from GitHub URLs
- π Multi-language Examples - Node, Go, Python, Java examples
- π One-Click Copy - Copy optimized Dockerfile instantly
- 𧬠Image Analysis - Inspect and analyze existing Docker images
- π Build Timeline - Visualize build process with cache efficiency
- π§ AI Suggestions - Get intelligent layer optimization recommendations
- βοΈ Interactive Wizard - Step-by-step Docker configuration guide
cd web
npm install
npm run dev # Development server on http://localhost:3000
npm run build # Production buildNote: For AI-powered features, set VITE_GEMINI_API_KEY in .env file:
VITE_GEMINI_API_KEY=your_api_key_hereGet your API key from Google AI Studio.
- 100% Local - All analysis runs locally in your browser/CLI
- No Data Collection - Your Dockerfile never leaves your machine
- Open Source - Full source code available for audit
- No Backend - No server, no database, no logging
- Node.js 18+
- npm or yarn
# Clone repository
git clone https://github.com/DangNgocDuong250903/dockeropt.git
cd dockeropt
# Install dependencies
npm install
# Build TypeScript
npm run build
# Run tests
npm test
# Lint code
npm run lintdockeropt/
βββ src/ # Core optimization engine (TypeScript)
β βββ cli.ts # CLI entry point
β βββ optimizer.ts # Main optimizer
β βββ rules.ts # Optimization rules
β βββ parser.ts # Dockerfile parser
β βββ ...
βββ web/ # Web interface
β βββ src/
β β βββ app.js # Main app logic
β β βββ components/ # UI components
β β βββ ...
β βββ ...
βββ examples/ # Example Dockerfiles
βββ dist/ # Compiled output
π Dockerfile Lint Results
HIGH (2):
1. Base image should use specific tag instead of 'latest'
Fix: Use 'node:18-alpine@sha256:...'
2. Container runs as root user
Fix: Add 'USER node' or create non-root user
{
"findings": [
{
"severity": "high",
"message": "Base image should use specific tag",
"lineNumber": 1,
"suggestion": "Use 'node:18-alpine@sha256:...'"
}
],
"metrics": {
"estimatedSizeSavings": 135,
"layerReduction": 3,
"securityScore": 85
}
}For integration with GitHub Advanced Security, CodeQL, and other security tools.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Docker Best Practices
- Google Gemini AI for AI-powered analysis
- All contributors and users of DockerOpt
- π Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
- π§ Contact: Open an issue on GitHub
If you find DockerOpt useful, please consider giving it a star on GitHub!
Made with β€οΈ by ΔαΊ·ng Ngα»c DΖ°Ζ‘ng