Overview
The Docker production deployment usesdocker-compose.production.yml to orchestrate all services:
- Django + Gunicorn: Application server
- PostgreSQL: Database with persistent volumes
- Redis: Cache and Celery message broker
- Traefik: Reverse proxy with automatic SSL via Let’s Encrypt
- Celery Worker: Background task processing
- Celery Beat: Scheduled task scheduler
- Flower: Celery monitoring (optional)
- AWS CLI: Database backup automation
All static and media files are served from S3/R2 in production. The
collectstatic command runs automatically during container startup.Prerequisites
1
Install Docker
Install Docker Engine and Docker Compose v2+:
2
Domain and DNS
- Register a domain name
- Point DNS A records to your server’s IP:
yourdomain.com→your.server.ipwww.yourdomain.com→your.server.ip
3
Firewall Configuration
Open required ports:
Deployment
1. Clone Repository
2. Configure Environment Files
Create production environment files by copying the template:- .envs/.production/.django
- .envs/.production/.postgres
Django application environment variables:
.envs/.production/.django
Generate SECRET_KEY:
python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'3. Configure Traefik
Create Traefik configuration for SSL certificates:compose/production/traefik/traefik.yml and update the domain and email:
compose/production/traefik/traefik.yml
4. Build Images
Build all production Docker images:footycollect_production_django(multi-stage build from compose/production/django/Dockerfile)footycollect_production_postgresfootycollect_production_traefikfootycollect_production_celeryworkerfootycollect_production_celerybeatfootycollect_production_flower
5. Start Services
On first startup, Django will automatically:
- Wait for PostgreSQL to be ready
- Run database migrations
- Collect static files to S3/R2
- Start Gunicorn
6. Create Superuser
Create an admin user:7. Verify Deployment
Check that all services are running:Service Management
Starting and Stopping
Viewing Logs
Running Management Commands
Database Management
Backups
Theawscli service can backup PostgreSQL to S3:
production_postgres_data_backups volume.
Restore
Static and Media Files
Static and media files are served from S3/R2 in production.Collect Static Files
Storage Configuration
Configure storage backend in.envs/.production/.django:
AWS S3
AWS S3
Cloudflare R2
Cloudflare R2
R2 requires CORS configuration if serving fonts or assets from a custom domain. See deploy/r2-cors-wrangler.json in the repository.
Updating the Application
1
Pull Latest Code
2
Rebuild Images
3
Run Migrations
4
Collect Static Files
5
Restart Services
6
Verify Deployment
Monitoring
Flower (Celery Monitoring)
Access Flower athttps://yourdomain.com:5555 (if port 5555 is exposed).
Container Health
Application Health
Troubleshooting
Container Won’t Start
Check logs
Check logs
Database connection errors
Database connection errors
Verify PostgreSQL environment variables match in both files:
.envs/.production/.postgres.envs/.production/.django(DATABASE_URL)
Environment file errors
Environment file errors
Ensure both environment files exist:Verify no syntax errors:
SSL Certificate Issues
Certificate not issued
Certificate not issued
Check Traefik logs:Verify DNS is pointing to your server:Ensure port 80 is accessible for HTTP challenge:
Certificate renewal failed
Certificate renewal failed
Remove existing certificates and restart:
Static Files Not Loading
Check S3/R2 credentials
Check S3/R2 credentials
Verify storage configuration:Test S3/R2 connectivity:
CORS errors (R2)
CORS errors (R2)
If using Cloudflare R2 with custom domain, configure CORS:See deploy/r2-cors-wrangler.json for CORS policy. Apply with:
Performance Issues
Increase Gunicorn workers
Increase Gunicorn workers
Edit compose/production/django/start:Recommended workers:
(2 * CPU cores) + 1Check resource limits
Check resource limits
Security Hardening
Firewall Rules
Docker Security
Environment Security
- Never commit
.envs/.production/to version control - Use strong passwords for
POSTGRES_PASSWORDandSECRET_KEY - Rotate
SECRET_KEYand database credentials regularly - Restrict access to environment files:
Next Steps
Environment Setup
Complete guide to all production environment variables
Production Checklist
Verify all security and configuration settings