运行docker-compose -f production.yml up最终将返回:

postgres_1      |   Connection matched pg_hba.conf line 95: "host all all all md5"
django_1        | PostgreSQL is unavailable (sleeping)...
postgres_1      | 2018-03-21 07:48:35.575 UTC [120] FATAL:  password authentication failed for user "DbUsErName"
postgres_1      | 2018-03-21 07:48:35.575 UTC [120] DETAIL:  Password does not match for user "DbUsErName".

在我的.envs / .production / .postgres中,我的环境以这种方式布置:
# PostgreSQL
# ------------------------------------------------------------------------------
POSTGRES_DB=luup
POSTGRES_USER=DbUsErName
POSTGRES_PASSWORD=myVeryYLongPW

在出现上述错误之前,终端还将输出:
celeryworker_1  | /entrypoint.sh: line 13: POSTGRES_USER: parameter not set

但是,它似乎确实是在compose / production / django / entrypoint.sh的此文件中设置的:
set -o errexit
set -o pipefail
set -o nounset


cmd="$@"

if [ -z "${POSTGRES_USER}" ]; then
    # the official postgres image uses 'postgres' as default user if not set explictly.
    export POSTGRES_USER=postgres
fi
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}"

自启动项目以来,我并没有涉及过太多的postgres配置,因为这只是尝试使其在Heroku上启动并运行。所以我还没有进入psql

我需要做些什么才能启动并运行它?

请让我知道是否需要其他信息。

编辑--production.yml:
version: '2'

volumes:
  postgres_data: {}
  postgres_backup: {}
  caddy: {}

services:
  django: &django
    build:
      context: .
      dockerfile: ./compose/production/django/Dockerfile
    depends_on:
      - postgres
      - redis
    env_file:
      - ./.envs/.production/.django
      - ./.envs/.production/.postgres
      - ./.envs/.production/.celery
    command: /gunicorn.sh

  postgres:
    build:
      context: .
      dockerfile: ./compose/production/postgres/Dockerfile
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - postgres_backup:/backups
    env_file:
      - ./.envs/.production/.postgres

  caddy:
    build:
      context: .
      dockerfile: ./compose/production/caddy/Dockerfile
    depends_on:
      - django
    volumes:
      - caddy:/root/.caddy
    env_file:
      - ./.envs/.production/.caddy
    ports:
      - "0.0.0.0:80:80"
      - "0.0.0.0:443:443"

  redis:
    image: redis:3.0

  celeryworker:
    <<: *django
    depends_on:
     - postgres
     - redis
    env_file:
      - ./.envs/.production/.celery
    command: /start-celeryworker.sh

  celerybeat:
    <<: *django
    depends_on:
      - postgres
      - redis
    env_file:
      - ./.envs/.production/.celery
    command: /start-celerybeat.sh

最佳答案

Postgres容器在第一次运行时通过env变量创建用户。因此,为了使其具有新值(生产用户名和密码),您可能必须重新构建它。

  • docker-compose stop postgres
  • docker-compose rm postgres
  • docker-compose -f production.yml up
  • 关于postgresql - Docker-compose up无法验证Postgres用户,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49400928/

    10-16 21:41