首页 > 解决方案 > 用户“postgres”的 Docker postgres 9.4 密码身份验证失败

问题描述

我正在运行非常基本docker-compose的跟踪docker-compose.yml并收到以下错误。

码头工人-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 以更新密码,但这是一种解决方法。有人对此有任何具体的解决方案吗?

标签: postgresqldockerdocker-compose

解决方案


我终于想通了,很高兴分享mistake我所做的事情。

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

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

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

但是 docker-compose 给出的错误并没有清楚地解释这种情况。

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


推荐阅读