简体   繁体   English

Docker Django、redis 和 ZD48BAC364AD5E16C8A0B13F87D5AE9DZconf

[英]Docker Django, redis and celery conf

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. 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.拒绝连接。

Here is my file docker-compose.yml这是我的文件 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

celery and redis are running in different containers. celeryredis在不同的容器中运行。

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.根据您分享的错误消息,您的celery很可能正在尝试连接到localhost以访问RedisDB ,该 RedisDB不在localhost 上。

Seach for the celery configuration file that contains the CELERY_BROKER_URL and CELERY_RESULT_BACKEND values.搜索包含CELERY_BROKER_URLCELERY_RESULT_BACKEND值的 celery 配置文件。 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:它们应该看起来像这样,指向您在撰写文件中定义的 redis 服务名称:

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:如果你没有这样的配置,直接搜索 Celery 实例初始化的地方,确保它看起来像这样:

app = Celery('server', broker='redis://redis:6379/0')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM