用户“postgres”的Docker postgres 9.4密码身份验证失败

时间:2021-03-03 12:55:18

标签: postgresql docker docker-compose

我正在运行非常基本的 docker-compose 并遵循 docker-compose.yml 并出现以下错误。

docker-compose.yml

services:
  redis:
    image: redis
  db:
    image: postgres:9.4
    environment:
      - POSTGRES_USER=udcoker
      - POSTGRES_PASSWORD=udcoker
      - POSTGRES_DB=docker
  vote:
    image: voting-app
    ports:
      - 5000:80
    depends_on:
      - redis
  worker:
    image: worker-app
    depends_on:
      - redis
      - db
    environment:
      - POSTGRES_USER=udcoker
      - POSTGRES_PASSWORD=udcoker
      - POSTGRES_DB=docker
  result:
    image: result-app
    ports:
      - 5001:80
    depends_on:
      - db
    environment:
      - POSTGRES_USER=udcoker
      - POSTGRES_PASSWORD=udcoker
      - POSTGRES_DB=docker

产生错误,

db_1      | vacuuming database template1 ... ok
db_1      | copying template1 to template0 ... ok
db_1      | copying template1 to postgres ... ok
db_1      | syncing data to disk ...
db_1      | WARNING: enabling "trust" authentication for local connections
db_1      | You can change this by editing pg_hba.conf or using the option -A, or
db_1      | --auth-local and --auth-host, the next time you run initdb.
db_1      | ok
db_1      |
db_1      | Success. You can now start the database server using:
db_1      |
db_1      |     postgres -D /var/lib/postgresql/data
db_1      | or
db_1      |     pg_ctl -D /var/lib/postgresql/data -l logfile start
db_1      |
db_1      | waiting for server to start....LOG:  database system was shut down at 2021-03-03 12:45:13 UTC
db_1      | LOG:  MultiXact member wraparound protections are now enabled
db_1      | LOG:  database system is ready to accept connections
db_1      | LOG:  autovacuum launcher started
worker_1  | Waiting for db
result_1  | Waiting for db
db_1      |  done
db_1      | server started
db_1      | CREATE DATABASE
db_1      |
db_1      |
db_1      | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
db_1      |
db_1      | LOG:  received fast shutdown request
db_1      | LOG:  aborting any active transactions
db_1      | LOG:  autovacuum launcher shutting down
db_1      | waiting for server to shut down....LOG:  shutting down
db_1      | LOG:  database system is shut down
worker_1  | Waiting for db
result_1  | Waiting for db
db_1      |  done
db_1      | server stopped
db_1      |
db_1      | PostgreSQL init process complete; ready for start up.
db_1      |
db_1      | LOG:  database system was shut down at 2021-03-03 12:45:15 UTC
db_1      | LOG:  MultiXact member wraparound protections are now enabled
db_1      | LOG:  database system is ready to accept connections
db_1      | LOG:  autovacuum launcher started
db_1      | FATAL:  password authentication failed for user "postgres"
db_1      | DETAIL:  Connection matched pg_hba.conf line 95: "host all all all md5"
db_1      | FATAL:  password authentication failed for user "postgres"
db_1      | DETAIL:  Connection matched pg_hba.conf line 95: "host all all all md5" 

我检查了各种 stackoverflow 现有问题,但没有一个解决实际问题。有人建议运行 postgres docker 并对其进行 bash 以更新密码,但这是一种解决方法。有人对此有任何具体的解决方案吗?

1 个答案:

答案 0 :(得分:0)

我终于想通了,很高兴分享mistake我做了什么。

如问题中所述,我通过在 db 服务的 environment 文件中提供 docker-compose.yml 变量来更改数据库配置,

environment:
      - POSTGRES_USER=udcoker
      - POSTGRES_PASSWORD=udcoker
      - POSTGRES_DB=docker

但同样需要在所有其他自定义服务(开源 github)中更新,这些服务尝试使用相同的用户/密码/数据库连接到此 depende-on postgres 数据库,但尚未完成。

然而 docker-compose 给出的错误并没有清楚地说明情况。

总而言之,我在连接属性中使用上述用户名/密码/数据库更新了应用程序,并且容器已启动。