It is simpler to run all processes in the single container. However, you can run each process in a separate container. They will communicate with each other through broker and results backend.
Here is my example repository that is using Django, Celery, RabbitMQ and Redis. Additionally, Django serves REST API (wsgi
server for DRF) and WebSockets (asgi
server for Django Channels). Every process is running in separate container but they do have common codebase (all stored in single repository).
version: '2'
services:
nginx:
restart: always
image: nginx:1.12-alpine
ports:
- 8000:8000
volumes:
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
- static_volume:/app/backend/server/django_static
client:
build:
context: .
dockerfile: ./docker/client/Dockerfile
restart: always
ports:
- 5001:5000
expose:
- 5000
postgres:
restart: always
image: postgres:9.5.6-alpine
volumes:
- ./docker/postgres/data:/var/lib/postgresql
ports:
- 5433:5432
expose:
- 5432
environment:
FILLA_DB_USER: tasks_user
FILLA_DB_PASSWORD: tasks_password
FILLA_DB_DATABASE: simple_tasks
POSTGRES_USER: postgres
volumes:
- ./docker/postgres/init-user-db.sh:/docker-entrypoint-initdb.d/init-user-db.sh
redis:
image: redis:3.0-alpine
restart: unless-stopped
ports:
- 6378:6379
rabbitmq:
image: rabbitmq:3.7-alpine
restart: unless-stopped
wsgiserver:
extends:
file: docker-common.yml
service: backend
entrypoint: /app/docker/backend/wsgi-entrypoint.sh
volumes:
- static_volume:/app/backend/server/django_static
links:
- postgres
- redis
- rabbitmq
expose:
- 8000
asgiserver:
extends:
file: docker-common.yml
service: backend
entrypoint: /app/docker/backend/asgi-entrypoint.sh
links:
- postgres
- redis
- rabbitmq
expose:
- 9000
worker:
extends:
file: docker-common.yml
service: backend
entrypoint: /app/docker/backend/worker-entrypoint.sh
links:
- postgres
- redis
- rabbitmq
redislistener:
extends:
file: docker-common.yml
service: backend
entrypoint: /app/docker/backend/redis-listener-entrypoint.sh
links:
- postgres
- redis
- rabbitmq
workerlistener:
extends:
file: docker-common.yml
service: backend
entrypoint: /app/docker/backend/worker-listener-entrypoint.sh
links:
- postgres
- redis
- rabbitmq
volumes:
static_volume: {}
For small projects I would go with keeping all processes in the single container and for larger projects that need scaling I would go with multiple containers.
command
andenvironment
statements on your docker-compose to run one as regular django and one as celery – Bellyful