January 30, 2025

About

To implement asynchronous processing with Celery, RabbitMQ and Redis are commonly used as part of the tech stack. Having a simple docker-compose setup ready for testing purposes can be extremely convenient. Below is an example of such a file.

To see the usage of Celery itslef, it would be good to view this article.

docker-compose.yml

services:
  rabbitmq:
    image: rabbitmq:3-management
    container_name: rabbitmq
    ports:
      - "5672:5672"  # AMQP PORT
      - "15672:15672" # UI
    environment:
      RABBITMQ_DEFAULT_USER: guest
      RABBITMQ_DEFAULT_PASS: guest

  redis:
    image: redis:alpine
    container_name: redis
    ports:
      - "6379:6379"

  celery:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: celery
    depends_on:
      - rabbitmq
      - redis
    environment:
      CELERY_BROKER_URL: "amqp://guest:guest@rabbitmq:5672//"
      CELERY_RESULT_BACKEND: "redis://redis:6379/0"
    command: python -m my_celery_worker