Overview
Template Worker includes Docker support for containerized deployments. This guide covers building Docker images, using Docker Compose, and configuring the container environment.Dockerfile
The project includes a multi-stage Dockerfile for building optimized production images:Key Features
- Build Caching: Uses Docker build cache mounts for faster rebuilds
- Offline SQLx: Compiles with
SQLX_OFFLINE=trueto avoid database dependency during build - Port 60000: Default HTTP API port for health checks and RPC
Building the Image
Docker Compose Setup
Template Worker includes a comprehensivedocker-compose.yml that orchestrates the entire stack including dependencies.
Full Stack Architecture
The compose file defines a multi-service architecture:- template-worker: The main worker service
- postgres: PostgreSQL database
- sandwich: Discord gateway proxy
- nirn_proxy: Discord REST API proxy with rate limiting
- seaweed: Object storage (SeaweedFS)
- api_exposer: Nginx reverse proxy
Template Worker Service
Network Configuration
The compose file uses three networks for security isolation:Running with Docker Compose
Create configuration file
Create a
config.docker.yaml file in your project root. See Configuration for details.Container Configuration
Environment Variables
| Variable | Description | Default |
|---|---|---|
RUST_LOG | Logging level (e.g., template-worker=info) | info |
MESOPHYLL_CLIENT_TOKEN | Token for process pool workers (internal use) | Auto-generated |
Volume Mounts
- Config: Mount
config.yamlas read-only at/app/config.yaml - Data: Persistent data is stored in named volumes (postgres, seaweed)
Port Mappings
The default compose setup exposes these ports to the host:| Port | Service | Purpose |
|---|---|---|
| 5600 | api_exposer | HTTP API access |
| 5601 | api_exposer | SeaweedFS access |
| 29334 | sandwich | Gateway API (testing) |
| 3222 | nirn_proxy | REST proxy (testing) |
| 3931 | sandwich | Prometheus metrics |
Health Checks
The template-worker service includes a health check endpoint:- Interval: 3 seconds
- Timeout: 10 seconds
- Retries: 100 (to allow for slow startup)
Troubleshooting
Worker Won’t Start
-
Check dependency health:
- Verify postgres and sandwich are healthy before worker starts
-
Check logs:
Connection Issues
- Ensure
config.yamluses Docker service names (e.g.,postgres, notlocalhost) - Verify network configuration allows internal service communication
- Check that secrets files are mounted correctly for nirn_proxy and sandwich
Performance Issues
See Scaling for container resource limits and worker pool configuration.Production Considerations
- Secrets Management: Use Docker secrets or environment files for sensitive data
- Resource Limits: Set memory and CPU limits in compose file
- Logging: Configure log rotation to prevent disk exhaustion
- Monitoring: Export Prometheus metrics from sandwich (port 3931)
- Backups: Regularly backup postgres and seaweed volumes