Skip to main content

The Customizable AI Dockerfile Generation Framework

Project description

DockAI 🐳🤖

The Customizable AI Dockerfile Generation Framework

Version Python License LangGraph

DockAI is an intelligent, adaptive framework that generates production-ready Dockerfiles for any project using Large Language Models (LLMs). It goes beyond simple template generation by understanding your codebase through RAG (Retrieval-Augmented Generation), analyzing your project architecture, and iteratively improving Dockerfiles until they pass all security and validation checks.

🌟 Key Features

🧠 Intelligent Context Understanding

  • RAG-Powered Analysis: Uses semantic embeddings (sentence-transformers) to understand your entire codebase
  • AST Code Intelligence: Extracts entry points, ports, environment variables, and framework dependencies automatically
  • Multi-Language Support: Works with JavaScript/TypeScript, Python, Go, Java, Ruby, PHP, .NET, and more

🏗️ Multi-Agent Architecture

DockAI v4.0 features a sophisticated multi-agent system orchestrated by LangGraph:

  • Analyzer Agent: Project discovery and technology stack detection
  • Blueprint Agent: Architectural planning and runtime configuration
  • Generator Agent: Dockerfile creation with best practices
  • Reviewer Agent: Security auditing and vulnerability detection
  • Reflector Agent: Failure analysis and adaptive learning
  • Iterative Improver Agent: Surgical fixes based on validation feedback

🔄 Adaptive & Self-Improving

  • Automatic Validation: Builds and tests the Docker image locally
  • Iterative Refinement: Learns from failures and auto-fixes issues (up to configurable retries)
  • Smart Fallback: Reverts to the last working Dockerfile if fixes fail (ignoring non-critical warnings)
  • Smart Reflection: AI analyzes build/runtime errors and adjusts strategy
  • Reanalysis: Detects when fundamental assumptions are wrong and pivots

🔒 Security & Best Practices

  • Hadolint Integration: Strict Dockerfile linting (warnings are treated as errors and auto-fixed)
  • Trivy Security Scanning: Container vulnerability detection
  • AI Security Review: Identifies security anti-patterns (root users, exposed secrets, etc.)
  • Multi-Stage Builds: Optimizes for smaller, more secure images

🎯 Production-Ready Features

  • Health Check Detection: Auto-discovers and configures health endpoints
  • Resource Optimization: Configurable memory, CPU, and process limits
  • Multi-Platform Support: Works with Docker, Podman, and GitHub Actions
  • Observability: OpenTelemetry and LangSmith tracing support

🛠️ Highly Customizable

  • Multi-LLM Support: OpenAI, Google Gemini, Anthropic Claude, Azure OpenAI, Ollama
  • Per-Agent Model Selection: Choose different models for different tasks (cost vs. quality)
  • Custom Instructions: Override default agent behavior
  • Custom Prompts: Complete control over AI reasoning
  • Environment-Based Configuration: 100+ configuration options via environment variables

🏛️ Architecture

DockAI v4.0 is built on a modern, agent-based architecture using LangGraph for workflow orchestration:

flowchart TD
    Start([START]) --> Scan[scan_node<br/>File Scanner]
    Scan --> Analyze[analyze_node<br/>AI Analyzer<br/><i>Detects project type & stack</i>]
    Analyze --> ReadFiles[read_files_node<br/>RAG Retrieval<br/><i>Semantic search for context</i>]
    ReadFiles --> Blueprint[blueprint_node<br/>Chief Architect<br/><i>Plans build strategy</i>]
    Blueprint --> Generate[generate_node<br/>Dockerfile Builder<br/><i>Creates Dockerfile</i>]
    
    Generate --> Review[review_node<br/>Security Auditor]
    
    Review --> ShouldRetryReview{Should<br/>Retry?}
    ShouldRetryReview -->|security_passed| Validate
    ShouldRetryReview -->|security_failed| Reflect
    ShouldRetryReview -->|max_retries| Stop([END<br/>✗ Max Retries])
    
    Validate[validate_node<br/>Test Engineer<br/><i>Docker build + validation</i>] --> ShouldRetry{Should<br/>Retry?}
    ShouldRetry -->|success| End([END<br/>✓ Dockerfile Ready])
    ShouldRetry -->|failure| Reflect[reflect_node<br/>Post-Mortem Analyst<br/><i>Analyzes failure</i>]
    ShouldRetry -->|max_retries| Stop
    
    Reflect --> Increment[increment_retry<br/>Update retry count]
    Increment --> NeedsReanalysis{Needs<br/>Reanalysis?}
    NeedsReanalysis -->|fundamental_issue| Analyze
    NeedsReanalysis -->|strategy_change| Blueprint
    NeedsReanalysis -->|fixable_error| Generate

Core Components

  • LangGraph Workflow Engine: Orchestrates the agent flow with conditional routing
  • RAG Context Engine: In-memory vector store for semantic code search
  • Multi-Agent System: 8 specialized AI agents for different tasks
  • Validation Pipeline: Docker build, Hadolint, Trivy, and health checks
  • State Management: Centralized state for workflow coordination

For detailed architecture documentation, see docs/architecture.md.

🎯 Three Ways to Use DockAI

DockAI can be integrated into your workflow in multiple ways, depending on your needs:

1️⃣ CLI Tool (Local Development)

Install via pip or uv and use directly from the command line:

Using pip:

pip install dockai-cli
export OPENAI_API_KEY="your-key"
dockai build .

Using uv (faster):

# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install DockAI
uv pip install dockai-cli

# Use it
dockai build .

Perfect for:

  • Local development and testing
  • Quick Dockerfile generation
  • Iterating on containerization

2️⃣ GitHub Actions (CI/CD Automation)

Integrate DockAI into your CI/CD pipeline with the GitHub Action:

name: Generate Dockerfile
on: [push]

jobs:
  dockerize:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Generate Dockerfile with DockAI
        uses: itzzjb/dockai@v4
        with:
          openai_api_key: ${{ secrets.OPENAI_API_KEY }}
          project_path: '.'
      
      - name: Commit Dockerfile
        run: |
          git config user.name "DockAI Bot"
          git add Dockerfile
          git commit -m "chore: update Dockerfile"
          git push

Perfect for:

  • Automated Dockerfile updates
  • Multi-service monorepos
  • Continuous integration workflows
  • Team collaboration

Learn more: GitHub Actions Guide

3️⃣ MCP Integration (Model Context Protocol)

Use DockAI as an MCP server with AI assistants like Claude Desktop:

Setup MCP:

{
  "mcpServers": {
    "dockai": {
      "command": "uvx",
      "args": ["dockai-cli"]
    }
  }
}

Usage with Claude Desktop:

You: Can you dockerize this Node.js project?
Claude: [Uses DockAI MCP] I'll generate a Dockerfile for your project...

Perfect for:

  • Interactive AI-assisted development
  • Natural language Dockerfile generation
  • Integration with Claude Desktop, VSCode, and other MCP clients
  • Conversational containerization workflow

Learn more: MCP Integration Guide


🚀 Quick Start

Prerequisites

  • Python 3.10 or higher
  • Docker installed and running
  • An API key from at least one LLM provider (OpenAI, Google, Anthropic, etc.)

Installation

Option 1: Install from PyPI (Recommended)

pip install dockai-cli

Option 2: Install with uv (Faster)

uv is an extremely fast Python package installer and resolver:

# Install uv (if not already installed)
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install DockAI
uv pip install dockai-cli

Why use uv?

  • 🚀 10-100x faster than pip
  • 📦 Drop-in replacement for pip
  • 🔒 Deterministic dependency resolution

Option 3: Install from Source

git clone https://github.com/itzzjb/dockai.git
cd dockai
pip install -e .

Basic Usage

  1. Set up your API key (choose one provider):
# OpenAI (Default)
export OPENAI_API_KEY="your-api-key-here"

# Or Google Gemini
export GOOGLE_API_KEY="your-api-key-here"
export DOCKAI_LLM_PROVIDER="gemini"

# Or Anthropic Claude
export ANTHROPIC_API_KEY="your-api-key-here"
export DOCKAI_LLM_PROVIDER="anthropic"
  1. Navigate to your project and run DockAI:
cd /path/to/your/project
dockai build .
  1. Done! Your production-ready Dockerfile will be created and validated.

Example Output

🔍 Scanning project...
✓ Found 42 files

🧠 Analyzing project with AI...
✓ Detected: Node.js Express application
✓ Entry point: src/server.js
✓ Dependencies: package.json

📖 Reading files with RAG (10 relevant chunks)...
✓ Context retrieved

🏗️ Creating architectural blueprint...
✓ Multi-stage build planned
✓ Health endpoint: /health

🔨 Generating Dockerfile...
✓ Dockerfile created

🔍 Reviewing security...
✓ No critical issues found

🧪 Validating with Docker...
✓ Image built successfully (142 MB)
✓ Container started
✓ Health check passed

✅ Dockerfile generated successfully!

📚 Documentation

Comprehensive documentation is available in the docs/ directory:

🎯 Use Cases

Single Project Dockerization

# Automatically detects and handles any project type
cd /path/to/your/project
dockai build .

Polyglot Projects

# Works with multi-language projects
dockai build ./my-fullstack-app

Microservices Architecture

# Generate optimized Dockerfiles for each service
for service in api frontend worker; do
  dockai build ./services/$service
done

Custom Requirements

# Add specific requirements for your organization
export DOCKAI_GENERATOR_INSTRUCTIONS="Always use Alpine Linux and pin all versions. Include MAINTAINER label."
dockai build .

Cost-Optimized Generation

# Use cheaper models for analysis, powerful models for generation
export DOCKAI_MODEL_ANALYZER="gpt-4o-mini"
export DOCKAI_MODEL_GENERATOR="gpt-4o"
dockai build .

⚙️ Configuration

DockAI offers extensive configuration through environment variables:

Model Selection

# Use different models for different agents (cost optimization)
export DOCKAI_MODEL_ANALYZER="gpt-4o-mini"      # Fast, cheap model for analysis
export DOCKAI_MODEL_GENERATOR="gpt-4o"          # Powerful model for generation
export DOCKAI_MODEL_REFLECTOR="gemini-1.5-pro"  # Strong reasoning for failure analysis

Security & Validation

export DOCKAI_SKIP_HADOLINT="false"            # Enable Dockerfile linting
export DOCKAI_SKIP_SECURITY_SCAN="false"       # Enable Trivy scanning
export DOCKAI_STRICT_SECURITY="true"           # Fail on any vulnerability
export DOCKAI_MAX_IMAGE_SIZE_MB="500"          # Max acceptable image size

RAG Configuration

export DOCKAI_USE_RAG="true"                   # Enable RAG (default in v4.0)
export DOCKAI_EMBEDDING_MODEL="all-MiniLM-L6-v2"  # Embedding model
export DOCKAI_READ_ALL_FILES="true"            # Read all source files

Retry & Adaptation

export MAX_RETRIES="3"                         # Max attempts to fix failures

For complete configuration options, see docs/configuration.md.

🧪 Testing

Run the test suite:

# Install test dependencies
pip install -e ".[test]"

# Run all tests
pytest

# Run with coverage
pytest --cov=src/dockai --cov-report=html

🤝 Contributing

Contributions are welcome! Please see our Contributing Guide for details.

🗺️ Roadmap

  • Support for Docker Compose generation
  • .dockerignore file generation
  • Multi-stage build optimization advisor
  • Integration with container registries
  • Web UI for interactive generation
  • Plugin system for custom validators

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • LangGraph for the agent orchestration framework
  • LangChain for LLM abstractions and tools
  • Sentence Transformers for efficient embeddings
  • All the open-source projects that make DockAI possible

📧 Support


Made with ❤️ by Januda Bethmin

⭐ If you find DockAI useful, please give it a star on GitHub!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dockai_cli-4.0.7.tar.gz (172.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dockai_cli-4.0.7-py3-none-any.whl (146.7 kB view details)

Uploaded Python 3

File details

Details for the file dockai_cli-4.0.7.tar.gz.

File metadata

  • Download URL: dockai_cli-4.0.7.tar.gz
  • Upload date:
  • Size: 172.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dockai_cli-4.0.7.tar.gz
Algorithm Hash digest
SHA256 b3e062850576a96c23f6540bab33ab4001b4b157b830c55156dbbc07285bc56c
MD5 1469ffa3bc901486f030663ff5409e6d
BLAKE2b-256 860d1e79db686756a6121315e0137613080500665fbd6bfee8e848b52ac3f99d

See more details on using hashes here.

File details

Details for the file dockai_cli-4.0.7-py3-none-any.whl.

File metadata

  • Download URL: dockai_cli-4.0.7-py3-none-any.whl
  • Upload date:
  • Size: 146.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dockai_cli-4.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 8e0de8b1c1d8e87964a40107de0f6d0be8ba79170778f088010168220b84adc0
MD5 48edd565341ba004d5b2ffeb1b342d7d
BLAKE2b-256 615ba237dfcdfb0fd41630fc4ac562beafd87b30d6a988d39761bc89415a9e1c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page