【问题标题】:PostgreSQL : Is the server running on host "localhost" (::1) and accepting errorPostgreSQL:服务器是否在主机“localhost”(::1)上运行并接受错误
【发布时间】: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


    【解决方案1】:

    在搜索时发现了这个。我会将我的解决方案分享给其他发现此问题的人。

    对我来说,问题在于 ${POSTGRES_HOST} 主机设置为 localhost。应该设置为database

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-20
      • 1970-01-01
      • 2021-11-29
      • 2018-12-17
      • 1970-01-01
      • 1970-01-01
      • 2017-06-09
      • 1970-01-01
      相关资源
      最近更新 更多