Skip to main content
Deploy FootyCollect to production using Docker Compose with a complete stack including Django, PostgreSQL, Redis, Traefik (reverse proxy with SSL), Celery workers, and AWS CLI for backups.

Overview

The Docker production deployment uses docker-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.comyour.server.ip
    • www.yourdomain.comyour.server.ip
3

Firewall Configuration

Open required ports:

Deployment

1. Clone Repository

Build context must be the repository root. All Docker Compose commands must run from /opt/footycollect.

2. Configure Environment Files

Create production environment files by copying the template:
Create two environment files:
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())'
See the environment setup guide for detailed variable descriptions.

3. Configure Traefik

Create Traefik configuration for SSL certificates:
Edit compose/production/traefik/traefik.yml and update the domain and email:
compose/production/traefik/traefik.yml

4. Build Images

Build all production Docker images:
This builds:
  • footycollect_production_django (multi-stage build from compose/production/django/Dockerfile)
  • footycollect_production_postgres
  • footycollect_production_traefik
  • footycollect_production_celeryworker
  • footycollect_production_celerybeat
  • footycollect_production_flower

5. Start Services

On first startup, Django will automatically:
  1. Wait for PostgreSQL to be ready
  2. Run database migrations
  3. Collect static files to S3/R2
  4. 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

The awscli service can backup PostgreSQL to S3:
Backups are stored in the production_postgres_data_backups volume.

Restore

Restoring a backup will overwrite the current database. Always create a backup before restoring.

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:
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 at https://yourdomain.com:5555 (if port 5555 is exposed).
Secure Flower with authentication in production. Do not expose it publicly without protection.

Container Health

Application Health

Troubleshooting

Container Won’t Start

Verify PostgreSQL environment variables match in both files:
  • .envs/.production/.postgres
  • .envs/.production/.django (DATABASE_URL)
Check PostgreSQL is ready:
Ensure both environment files exist:
Verify no syntax errors:

SSL Certificate Issues

Check Traefik logs:
Verify DNS is pointing to your server:
Ensure port 80 is accessible for HTTP challenge:
Remove existing certificates and restart:

Static Files Not Loading

Verify storage configuration:
Test S3/R2 connectivity:
If using Cloudflare R2 with custom domain, configure CORS:See deploy/r2-cors-wrangler.json for CORS policy. Apply with:

Performance Issues

Edit compose/production/django/start:
Recommended workers: (2 * CPU cores) + 1
Add resource limits in docker-compose.production.yml:

Security Hardening

Complete the production checklist before deploying to production.

Firewall Rules

Docker Security

Environment Security

  • Never commit .envs/.production/ to version control
  • Use strong passwords for POSTGRES_PASSWORD and SECRET_KEY
  • Rotate SECRET_KEY and 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