Django Stack
A comprehensive Django production stack featuring Gunicorn as the WSGI server behind an Nginx reverse proxy. PostgreSQL 16 provides the primary relational database, while Redis 7 handles application caching and Celery result storage. RabbitMQ 3.13 acts as the AMQP message broker for Celery, with separate containers for the Celery worker and Celery Beat scheduler to process background tasks and periodic jobs. All services are connected through isolated frontend and backend networks, with health checks ensuring proper startup ordering. Resource limits are applied to every service and named volumes persist all stateful data.
Services Inclus
nginx
nginx:1.27-alpine
django
python:3.12-slim
Variables d'Environnement :
celery_worker
python:3.12-slim
Variables d'Environnement :
celery_beat
python:3.12-slim
Variables d'Environnement :
postgres
postgres:16-alpine
Variables d'Environnement :
redis
redis:7-alpine
rabbitmq
rabbitmq:3.13-management-alpine
Variables d'Environnement :
YAML Généré
# Generated by ComposeHub (composehub.dev)
name: django-stack
services:
nginx:
image: nginx:1.27-alpine
restart: unless-stopped
ports:
- 80:80
- 443:443
volumes:
- nginx_conf:/etc/nginx/conf.d
- static_data:/var/www/static:ro
- media_data:/var/www/media:ro
networks:
- frontend
depends_on:
django:
condition: service_healthy
healthcheck:
test:
- CMD
- curl
- "-f"
- http://localhost
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
deploy:
resources:
limits:
cpus: "0.50"
memory: 256M
reservations:
cpus: "0.10"
memory: 64M
labels:
com.composeforge.description: Nginx reverse proxy serving static files and proxying to Gunicorn
django:
image: python:3.12-slim
restart: unless-stopped
command:
- gunicorn
- config.wsgi:application
- "--bind"
- 0.0.0.0:8000
- "--workers"
- "4"
- "--threads"
- "2"
- "--timeout"
- "120"
- "--access-logfile"
- "-"
working_dir: /app
expose:
- "8000"
volumes:
- app_src:/app
- static_data:/app/staticfiles
- media_data:/app/media
environment:
DJANGO_SETTINGS_MODULE: ${DJANGO_SETTINGS_MODULE:-config.settings.production}
DJANGO_SECRET_KEY: ${DJANGO_SECRET_KEY:-change-this-secret-key}
DJANGO_ALLOWED_HOSTS: ${DJANGO_ALLOWED_HOSTS:-*}
DJANGO_DEBUG: ${DJANGO_DEBUG:-False}
DATABASE_URL: postgres://${POSTGRES_USER:-django}:${POSTGRES_PASSWORD:-changeme}@postgres:5432/${POSTGRES_DB:-django}
REDIS_URL: redis://redis:6379/0
CELERY_BROKER_URL: amqp://${RABBITMQ_USER:-guest}:${RABBITMQ_PASSWORD:-guest}@rabbitmq:5672/${RABBITMQ_VHOST:-/}
CELERY_RESULT_BACKEND: redis://redis:6379/1
networks:
- frontend
- backend
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
rabbitmq:
condition: service_healthy
healthcheck:
test:
- CMD-SHELL
- curl -f http://localhost:8000/health/ || exit 1
interval: 30s
timeout: 10s
retries: 5
start_period: 40s
deploy:
resources:
limits:
cpus: "2.00"
memory: 1024M
reservations:
cpus: "0.50"
memory: 256M
labels:
com.composeforge.description: Django application served by Gunicorn
celery_worker:
image: python:3.12-slim
restart: unless-stopped
command:
- celery
- "-A"
- config
- worker
- "--loglevel=info"
- "--concurrency=4"
- "--max-tasks-per-child=100"
working_dir: /app
volumes:
- app_src:/app
environment:
DJANGO_SETTINGS_MODULE: ${DJANGO_SETTINGS_MODULE:-config.settings.production}
DJANGO_SECRET_KEY: ${DJANGO_SECRET_KEY:-change-this-secret-key}
DATABASE_URL: postgres://${POSTGRES_USER:-django}:${POSTGRES_PASSWORD:-changeme}@postgres:5432/${POSTGRES_DB:-django}
REDIS_URL: redis://redis:6379/0
CELERY_BROKER_URL: amqp://${RABBITMQ_USER:-guest}:${RABBITMQ_PASSWORD:-guest}@rabbitmq:5672/${RABBITMQ_VHOST:-/}
CELERY_RESULT_BACKEND: redis://redis:6379/1
networks:
- backend
depends_on:
rabbitmq:
condition: service_healthy
redis:
condition: service_healthy
postgres:
condition: service_healthy
healthcheck:
test:
- CMD-SHELL
- celery -A config inspect ping --timeout 10 || exit 1
interval: 60s
timeout: 15s
retries: 3
start_period: 30s
deploy:
resources:
limits:
cpus: "1.00"
memory: 512M
reservations:
cpus: "0.25"
memory: 128M
labels:
com.composeforge.description: Celery worker processing asynchronous tasks
celery_beat:
image: python:3.12-slim
restart: unless-stopped
command:
- celery
- "-A"
- config
- beat
- "--loglevel=info"
- "--schedule=/tmp/celerybeat-schedule"
- "--pidfile=/tmp/celerybeat.pid"
working_dir: /app
volumes:
- app_src:/app
environment:
DJANGO_SETTINGS_MODULE: ${DJANGO_SETTINGS_MODULE:-config.settings.production}
DJANGO_SECRET_KEY: ${DJANGO_SECRET_KEY:-change-this-secret-key}
DATABASE_URL: postgres://${POSTGRES_USER:-django}:${POSTGRES_PASSWORD:-changeme}@postgres:5432/${POSTGRES_DB:-django}
CELERY_BROKER_URL: amqp://${RABBITMQ_USER:-guest}:${RABBITMQ_PASSWORD:-guest}@rabbitmq:5672/${RABBITMQ_VHOST:-/}
CELERY_RESULT_BACKEND: redis://redis:6379/1
networks:
- backend
depends_on:
rabbitmq:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test:
- CMD-SHELL
- test -f /tmp/celerybeat.pid && kill -0 $(cat /tmp/celerybeat.pid) || exit 1
interval: 60s
timeout: 10s
retries: 3
start_period: 30s
deploy:
resources:
limits:
cpus: "0.25"
memory: 128M
reservations:
cpus: "0.05"
memory: 64M
labels:
com.composeforge.description: Celery Beat periodic task scheduler
postgres:
image: postgres:16-alpine
restart: unless-stopped
command:
- postgres
- "-c"
- shared_buffers=256MB
- "-c"
- effective_cache_size=768MB
- "-c"
- work_mem=16MB
- "-c"
- maintenance_work_mem=128MB
- "-c"
- max_connections=100
volumes:
- postgres_data:/var/lib/postgresql/data
environment:
POSTGRES_DB: ${POSTGRES_DB:-django}
POSTGRES_USER: ${POSTGRES_USER:-django}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-changeme}
PGDATA: /var/lib/postgresql/data/pgdata
networks:
- backend
healthcheck:
test:
- CMD-SHELL
- pg_isready -U ${POSTGRES_USER:-django} -d ${POSTGRES_DB:-django}
interval: 15s
timeout: 5s
retries: 5
start_period: 30s
deploy:
resources:
limits:
cpus: "1.00"
memory: 512M
reservations:
cpus: "0.25"
memory: 256M
labels:
com.composeforge.description: PostgreSQL 16 primary database
redis:
image: redis:7-alpine
restart: unless-stopped
command:
- redis-server
- "--maxmemory"
- 128mb
- "--maxmemory-policy"
- allkeys-lru
- "--appendonly"
- yes
- "--appendfsync"
- everysec
volumes:
- redis_data:/data
networks:
- backend
healthcheck:
test:
- CMD
- redis-cli
- ping
interval: 15s
timeout: 5s
retries: 3
start_period: 10s
deploy:
resources:
limits:
cpus: "0.50"
memory: 192M
reservations:
cpus: "0.10"
memory: 64M
labels:
com.composeforge.description: Redis 7 cache and Celery result backend
rabbitmq:
image: rabbitmq:3.13-management-alpine
restart: unless-stopped
ports:
- 15672:15672
expose:
- "5672"
volumes:
- rabbitmq_data:/var/lib/rabbitmq
environment:
RABBITMQ_DEFAULT_USER: ${RABBITMQ_USER:-guest}
RABBITMQ_DEFAULT_PASS: ${RABBITMQ_PASSWORD:-guest}
RABBITMQ_DEFAULT_VHOST: ${RABBITMQ_VHOST:-/}
networks:
- backend
healthcheck:
test:
- CMD
- rabbitmq-diagnostics
- "-q"
- ping
interval: 30s
timeout: 10s
retries: 5
start_period: 30s
deploy:
resources:
limits:
cpus: "1.00"
memory: 512M
reservations:
cpus: "0.25"
memory: 256M
labels:
com.composeforge.description: RabbitMQ 3.13 AMQP message broker with management UI
networks:
frontend:
driver: bridge
backend:
driver: bridge
volumes:
app_src:
driver: local
static_data:
driver: local
media_data:
driver: local
postgres_data:
driver: local
redis_data:
driver: local
rabbitmq_data:
driver: local
nginx_conf:
driver: local
Informations Rapides
- Services
- 7
- Réseaux
- 2
- Volumes
- 7
Quand l'Utiliser
Ce modèle est idéal pour mettre en place un environnement django stack Tous les services sont préconfigurés avec des healthchecks, des limites de ressources et des valeurs par défaut raisonnables. Personnalisez les variables d'environnement avant de déployer en production.
Conseils
- Changez tous les mots de passe par défaut avant le déploiement
- Vérifiez les limites de ressources pour votre matériel
- Ajoutez un reverse proxy pour le HTTPS en production
- Configurez des stratégies de sauvegarde pour les volumes de données