【发布时间】:2023-03-23 15:05:02
【问题描述】:
Celery 无法在我的 docker 服务中连接到 PostgreSQL 并出现此错误
could not connect to server: Cannot assign requested address
celery_1 | Is the server running on host "localhost" (::1) and accepting
celery_1 | TCP/IP connections on port 5432?
虽然 PostgreSQL 对数据库工作正常,我能够执行操作,但它只是在 celery 的情况下。
我现在在这个芹菜服务中有 2 个案例
celery:
build:
context: ./
dockerfile: Dockerfile
command: celery -A sampleproject worker -l info
environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_HOST=${POSTGRES_HOST}
- POSTGRES_PORT=${POSTGRES_PORT}
volumes:
- .:/usr/src/app/
depends_on:
- database
- app
- redis
当我在 celery 环境中传递所有 PostgreSQL 变量 时,它的工作原理。当我删除它们时它不起作用。为什么会这样?我该如何解决这个问题?这样我就可以用正确的方式运行芹菜了
【问题讨论】:
标签: django postgresql docker celery