1

I dont know what part I am missing but celery not conneting to redis when I am running docker-compose up --build error: Cannot connect to redis://127.0.0.1:6379/0: Error 111 connecting to 127.0.0.1: 6379. Connection refused.

Here is my file docker-compose.yml

version: '3'
    
  services:
    web:
      build: .
      image: resolution
      depends_on:
        - db
        - redis
        - celery
      command: bash -c "python3 /code/manage.py migrate && python3 /code/manage.py initialsetup && python3 /code/manage.py runserver 0.0.0.0:8000"
      volumes:
        - .:/code
      ports:
        - "8000:8000"
      links:
        - db:db
        - redis:redis
        - celery:celery
      restart: always
      environment:
        - POSTGRES_DB=postgres
        - POSTGRES_USER=postgres
        - POSTGRES_PASSWORD=postgres
        - PGHOST=trust
        - PGPORT=5432
    db:
      image: postgres:latest
      environment:
        POSTGRES_DB: 'postgres'
        POSTGRES_PASSWORD: 'postgres'
        POSTGRES_USER: 'postgres'
        POSTGRES_HOST: 'trust'
    redis:
      image: "redis:alpine"
      ports:
      - "6379:6379"
      restart: on-failure
    celery:
      image: resolution
      command: celery -A mayan worker -l info
      environment:
        - DJANGO_SETTINGS_MODULE=mayan.settings.production
      volumes:
        - .:/code
      depends_on:
        - db
        - redis
      links:
        - redis:redis
      restart: on-failure

1 Answer 1

3

celery and redis are running in different containers.

According to the error message that you shared, most likely, your celery is trying to connect to localhost to reach the RedisDB, which is not on localhost.

Seach for the celery configuration file that contains the CELERY_BROKER_URL and CELERY_RESULT_BACKEND values. Most likely they look like this:

CELERY_BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'

They should look like this, pointing to the redis service name that you defined in your compose file:

CELERY_BROKER_URL = 'redis://redis:6379'
CELERY_RESULT_BACKEND = 'redis://redis:6379'

If you don't have such a config, search directly for the place where the Celery instance is initialized and make sure it looks like this:

app = Celery('server', broker='redis://redis:6379/0')
Sign up to request clarification or add additional context in comments.

1 Comment

THIS WAS THE ANSWER

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.