0

I am trying to integrate celery, rabbitmq with my django app and run it using docker, below is my docker-compose.yml file:

version: '3.4'

services:
  db:
    image: postgres:13.4
    env_file:
      - ./docker/env.db
    ports:
      - 5432:5432

  app: &app
    build:
      context: .
      dockerfile: ./docker/Dockerfile
    env_file:
      - ./docker/env.db
      - ./.env
    volumes:
      - .:/opt/code
    ports:
      - 8000:8000
      - 3000:3000
    depends_on:
      - db
      - rabbitmq
    command: bash ./scripts/runserver.sh
  
  rabbitmq:
    image: rabbitmq:3.7-alpine
    container_name: 'rabbitmq'
    ports:
      - "5672:5672"

  celery:
    <<: *app
    command: celery -A app worker --loglevel=info
    ports: []
    depends_on:
      - rabbitmq

However,I am getting this error:

celery_1    | [2022-01-22 07:03:36,373: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 111] Connection refused.
celery_1    | Trying again in 6.00 seconds... (3/100)

What should I do?

Help would be much appreciated.

Thank you!

Nabeel Hassan
  • 149
  • 1
  • 1
  • 9
  • 1
    Share your celery settings, please. I suspect you are pointing to a localhost in `CELERY_BROKER_URL`, change it to the hostname from docker-compose, i.e. `rabbitmq` instead of `127.0.0.1` – Ersain Jan 22 '22 at 07:43
  • Thank you so much, declaring a CELERY_BROKER_URL='rabbitmq' in my settings.py totally fixed the issue. – Nabeel Hassan Jan 22 '22 at 09:12

0 Answers0