Prerequisites
Ensure you have Docker and Docker Compose installed on your machine before proceeding.
- Docker: Version 20.10 or higher
- Docker Compose: Version 2.0 or higher
- Environment variables:
.envfile with required API keys
Quick start
Create .env file
Create a See environment variables for complete configuration.
.env file in the project root with your API keys:Build and run
Build the Docker image and start the services:The API will be available at
http://localhost:8000.Docker configuration
Dockerfile
The system uses a multi-stage build for optimized image size:- Multi-stage build reduces final image size
- Non-root user (
appuser) for security - Virtual environment isolation
- Only runtime dependencies in final image
docker-compose.yml
The Docker Compose configuration manages the service:- Port mapping:
8000:8000exposes the FastAPI server - Volumes: Persist data, models, and reports on the host
- Health check: Monitors service availability every 30 seconds
- Restart policy: Automatically restarts on failures
Volume mounts
The following directories are mounted for data persistence:| Volume | Purpose |
|---|---|
./reports | Evaluation reports and metrics |
./kb_docs | Knowledge base documents |
./artifacts | Trained ML models |
./chroma_db | Chroma vector database |
Common operations
Running in detached mode
Viewing logs
Stopping the service
Rebuilding after code changes
Accessing the container shell
Health checks
The container includes an automated health check:Production considerations
- Remove
.envfrom image: Use Docker secrets or environment variables instead of copying.envinto the image - Use specific base image tags: Pin
python:3.12-slimto a specific version (e.g.,python:3.12.1-slim) - Enable TLS: Place the service behind a reverse proxy (nginx, Traefik) with HTTPS
- Resource limits: Add CPU and memory constraints to
docker-compose.yml - Logging: Configure structured logging with log drivers
- Monitoring: Integrate with Prometheus/Grafana for metrics
Troubleshooting
Container fails to start
Container fails to start
Check logs:Common causes:
- Missing environment variables in
.env - Port 8000 already in use
- Insufficient disk space
Health check failing
Health check failing
Verify the service is running:Common causes:
- Application startup time exceeds timeout
- FastAPI server not listening on 0.0.0.0
- Missing dependencies
timeout and start_period in the healthcheck configuration.Volume permission errors
Volume permission errors
Error:
PermissionError: [Errno 13] Permission deniedCause: Volume directories created by Docker with root ownershipSolution:Image size too large
Image size too large
Check image size:Optimization tips:
- Multi-stage build already minimizes size
- Remove unnecessary dependencies from
pyproject.toml - Use
.dockerignoreto exclude test files and documentation - Consider using
python:3.12-alpinefor smaller base image
Next steps
Environment variables
Configure API keys and system settings
Production deployment
Deploy to production with monitoring and scaling
API reference
Explore the API endpoints
Data ingestion
Load documents into the knowledge base