Docker Compose for Django + Celery + Redis + PostgreSQL
Full Django production stack with async task processing, caching, and PostgreSQL.
python django celery redis postgres fullstack
compose.yaml
services:
web:
build: .
command: gunicorn myproject.wsgi:application --bind 0.0.0.0:8000
ports:
- target: 8000
mode: ingress
environment:
- DATABASE_URL=postgresql://postgres:${POSTGRES_PASSWORD}@db:5432/django
- REDIS_URL=redis://redis:6379/0
- DJANGO_SECRET_KEY=${DJANGO_SECRET_KEY}
- DJANGO_SETTINGS_MODULE=myproject.settings.production
healthcheck:
test:
- CMD
- curl
- -f
- http://localhost:8000/
interval: 30s
timeout: 5s
retries: 3
depends_on:
- db
- redis
deploy:
resources:
reservations:
cpus: "0.5"
memory: 256M
restart: unless-stopped
worker:
build: .
command: celery -A myproject worker --loglevel=info
environment:
- DATABASE_URL=postgresql://postgres:${POSTGRES_PASSWORD}@db:5432/django
- REDIS_URL=redis://redis:6379/0
- DJANGO_SECRET_KEY=${DJANGO_SECRET_KEY}
- DJANGO_SETTINGS_MODULE=myproject.settings.production
depends_on:
- db
- redis
deploy:
resources:
reservations:
cpus: "0.5"
memory: 256M
restart: unless-stopped
beat:
build: .
command: celery -A myproject beat --loglevel=info
environment:
- DATABASE_URL=postgresql://postgres:${POSTGRES_PASSWORD}@db:5432/django
- REDIS_URL=redis://redis:6379/0
- DJANGO_SECRET_KEY=${DJANGO_SECRET_KEY}
depends_on:
- db
- redis
deploy:
resources:
reservations:
cpus: "0.5"
memory: 256M
restart: unless-stopped
db:
image: postgres:16
ports:
- target: 5432
mode: host
environment:
- POSTGRES_DB=django
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
healthcheck:
test:
- CMD-SHELL
- pg_isready -U postgres
interval: 10s
timeout: 5s
retries: 5
deploy:
resources:
reservations:
cpus: "0.5"
memory: 256M
restart: unless-stopped
x-defang-postgres: true
redis:
image: redis:7-alpine
ports:
- target: 6379
mode: host
healthcheck:
test:
- CMD
- redis-cli
- ping
interval: 10s
timeout: 5s
retries: 5
deploy:
resources:
reservations:
cpus: "0.5"
memory: 256M
restart: unless-stopped
x-defang-redis: true
Services
- web .
- worker .
- beat .
- db postgres:16
- redis redis:7-alpine