Docker Setup¶
Generated projects include comprehensive Docker configuration for development and production.
Files Overview¶
| File | Purpose |
|---|---|
Dockerfile |
Production-ready multi-stage build |
docker-compose.yml |
Service orchestration |
.devcontainer/compose.yml |
Dev container services |
.devcontainer/compose-mcp.yml |
MCP server services |
Dockerfile¶
Multi-stage build optimized for size and security:
# Build stage
FROM python:3.12-slim AS builder
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
WORKDIR /app
COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-dev
COPY src/ src/
# Runtime stage
FROM python:3.12-slim AS runtime
RUN useradd --create-home --shell /bin/bash app
WORKDIR /app
COPY --from=builder --chown=app:app /app/.venv /app/.venv
COPY --from=builder --chown=app:app /app/src /app/src
USER app
ENV PATH="/app/.venv/bin:$PATH"
EXPOSE 8000
CMD ["python", "-m", "my_project.api.main"]
Key Features¶
- Multi-stage - Small final image (~150MB vs ~1GB)
- Non-root user - Security best practice
- uv for speed - Fast dependency installation
- Locked dependencies - Reproducible builds
Building Images¶
# Build production image
just docker-build
# or
docker build -t my-project:latest .
# Run container
just docker-run
# or
docker run -p 8000:8000 my-project:latest
Docker Compose¶
Production Services¶
docker-compose.yml:
services:
app:
build: .
ports:
- "8000:8000"
environment:
- DATABASE_URL=postgresql://postgres:postgres@db:5432/app
depends_on:
- db
db:
image: postgres:16-alpine
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=app
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:
Commands¶
# Start all services
just up
# or
docker compose up -d
# View logs
just logs
# or
docker compose logs -f
# Stop services
just down
# or
docker compose down
Dev Container Setup¶
Main Container¶
.devcontainer/compose.yml:
services:
dev:
build:
context: ..
dockerfile: .devcontainer/Dockerfile
volumes:
- ..:/workspace:cached
command: sleep infinity
MCP Services¶
.devcontainer/compose-mcp.yml:
services:
searxng:
image: searxng/searxng:latest
memgraph:
image: memgraph/memgraph-platform
# ... other MCP servers
Environment Variables¶
In docker-compose.yml¶
Using .env File¶
Networking¶
Service Discovery¶
Services can reach each other by name:
Port Mapping¶
Volumes¶
Named Volumes¶
Persist data between container restarts:
Bind Mounts¶
Mount local directories:
Health Checks¶
services:
app:
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
interval: 30s
timeout: 10s
retries: 3
Production Considerations¶
Security¶
- Use secrets management, not environment variables for sensitive data
- Run as non-root user
- Keep base images updated
Performance¶
- Use multi-stage builds
- Leverage build cache
- Consider Alpine-based images
Scaling¶
Next Steps¶
- Dev Containers - Full development environment
- MCP Servers - AI integrations