芹菜工人无法使用Django连接到Dockerized Redis实例



当前具有Dockerized Django应用程序,并打算使用芹菜处理长期运行的任务。但是docker-compose失败了以下错误:

[2018-12-17 17:25:59,710: ERROR/MainProcess] consumer: Cannot 
connect to redis://redis:6379//: Error -2 connecting to redis:6379. 
Name or service not known..

在SOF上也有一些类似的问题,但它们似乎都集中在celery_broker_url中。

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

我的docker-compose.yml:

db:
  image: postgres:10.1-alpine
  restart: unless-stopped
  volumes:
    - postgres_data:/var/lib/postgresql/data/
  networks:
    - dsne-django-nginx
django: &python
  restart: unless-stopped
  build:
  context: .
  networks:
    - dsne-django-nginx
  volumes:
    - dsne-django-static:/usr/src/app/static
    - dsne-django-media:/usr/src/app/media
  ports:
    - 8000:8000
  depends_on:
    - db
    - redis
    - celery_worker
nginx:
  container_name: dsne-nginx
  restart: unless-stopped
  build:
  context: ./nginx
  dockerfile: nginx.dockerfile
  networks:
    - dsne-django-nginx
  volumes:
    - dsne-django-static:/usr/src/app/static
    - dsne-django-media:/usr/src/app/media
    - dsne-nginx-cert:/etc/ssl/certs:ro
    - /etc/ssl/:/etc/ssl/
    - /usr/share/ca-certificates/:/usr/share/ca-certificates/
  ports:
    - 80:80
    - 443:443
  depends_on:
    - django
redis:
  image: redis:alpine
celery_worker:
  <<: *python
  command: celery -A fv1 worker --loglevel=info
  ports: []
  depends_on:
    - redis
    - db
volumes:
  postgres_data:
  dsne-django-static:
    driver: local
  dsne-django-media:
    driver: local
  dsne-nginx-cert:
networks:
  dsne-django-nginx:
    driver: bridge

init .py:

from .celery import fv1 as celery_app
__all__ = ('celery_app',)

芹菜:

    from __future__ import absolute_import, unicode_literals
    import os
    from celery import Celery
    import fv1
    # set the default Django settings module for the 'celery' program.
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'fv1.settings')
    app = Celery('fv1')
    # Using a string here means the worker doesn't have to serialize
    # the configuration object to child processes.
    # - namespace='CELERY' means all celery-related configuration keys
    #   should have a `CELERY_` prefix.
    app.config_from_object('django.conf:settings', namespace='CELERY')
    # Load task modules from all registered Django app configs.
    app.autodiscover_tasks()

    @app.task(bind=True)
    def debug_task(self):
        print('Request: {0!r}'.format(self.request))

我要在哪里出错,为什么我的芹菜工人不能连接到Redis?

您的redis容器不列出端口6379

相关内容

  • 没有找到相关文章

最新更新