Overview
Docker deployment packages the agent and all its dependencies into a container image, ensuring consistent behavior across different environments. This is the recommended approach for production deployments.Dockerfile Architecture
The project uses a multi-stage Docker build for optimal image size and build caching:Build Strategy
Multi-Stage Build
The Dockerfile uses two stages:1
Builder Stage
Installs Poetry and creates the virtual environment with all dependencies:
2
Runtime Stage
Creates a minimal runtime image with only the virtual environment and source code:
Building the Image
Basic Build
Build the Docker image from the project root:Build with Cache
The Dockerfile uses Docker’s cache mount for faster builds:Build with Version Tag
Tag your builds with version numbers for better tracking:Running Containers
Basic Run
Run a container with environment variables:Run with Environment File
Use a.env file for cleaner configuration:
Interactive Mode
Run a container with an interactive shell for debugging:Override Command
Override the default command to run a specific agent:Environment Configuration
Required Variables
The container CMD uses environment variables to specify the agent:System Environment Variables
The Docker image sets several system-level environment variables:string
default:"/app"
Python module search path, set to the application directory
string
default:"python"
Use pure Python implementation of Protocol Buffers
string
default:"1"
Disable transformers warnings (we only use for tokenization, not PyTorch)
string
default:"none"
Deployment version for Langfuse tracing (set via build arg in CI/CD)
System Dependencies
The runtime image includes system packages required by various Python libraries:- ffmpeg - Media processing (used by some AI models)
- libsm6 - Session management library
- libxext6 - X11 extensions library
Docker Compose
Single Agent Setup
Create adocker-compose.yml for easier management:
docker-compose.yml
Multiple Agents
Run multiple agents simultaneously:docker-compose.yml
With Database
Add a PostgreSQL database for agents that need persistence:docker-compose.yml
CI/CD Integration
GitHub Actions
The project includes automated Docker builds in.github/workflows/python_cd.yaml:
Image Registry
Images are automatically pushed to GitHub Container Registry (ghcr.io):Trigger Builds
1
Automatic on Main
Pushes to the
main branch automatically trigger builds2
Manual PR Builds
Add “build please” to PR description to trigger a build:
Image Optimization
Size Reduction
The multi-stage build reduces image size significantly:Without Multi-Stage
~2.5 GB (includes Poetry and build tools)
With Multi-Stage
~1.2 GB (runtime dependencies only)
Layer Caching
Optimize build times by ordering Dockerfile commands strategically:- Install system dependencies (rarely changes)
- Copy
pyproject.tomlandpoetry.lock(changes occasionally) - Install Python dependencies (cached until lockfile changes)
- Copy source code (changes frequently)
Build Cache Mount
The Poetry cache is mounted during build to avoid re-downloading packages:Monitoring and Logs
View Logs
Container Stats
Health Checks
Add a health check to your Docker Compose:Troubleshooting
Build Failures
Build Failures
If the build fails, try clearing the build cache:
Platform Issues
Platform Issues
The Dockerfile specifies
linux/amd64. If you’re on ARM (M1/M2 Mac), you may need:Out of Memory
Out of Memory
Increase Docker memory limits in Docker Desktop settings or add resource limits:
Missing Environment Variables
Missing Environment Variables
Ensure all required variables are set. Check logs:
Next Steps
Cloud Deployment
Deploy containers to Google Kubernetes Engine (GKE)
Environment Config
Complete environment variable reference
Local Development
Run agents locally without Docker
Contributing
Contribute to the project on GitHub