首页 > 解决方案 > Postgres docker“用户“postgres”没有分配密码。”

问题描述

我正在使用 docker 运行 Postgres 图像。它曾经在 Windows10 和 Ubuntu 18.04 上运行没有任何问题。

在 Ubuntu 系统上重新克隆项目password authentication failed for user "postgres"后,运行docker-compose up.

在 Ubuntu 系统上重新克隆项目之前,它可以正常运行,并且在 Windows10 系统上仍然可以正常运行。

我的docker-compose.yml

version: '2'

services:
  postgresql:
    image: 'bitnami/postgresql:latest'
    ports:
      - '5432:5432'
    environment:
      - POSTGRESQL_USERNAME=someuser
      - POSTGRESQL_PASSWORD=mysecretpassword
      - POSTGRESQL_DATABASE=mydatabase

我试图sudo docker system prune删除所有停止的容器及其未使用的网络。这并不能解决问题。

我需要更改/做什么才能使 Postgres 映像能够再次在 Ubuntu 系统上成功运行?

完整的错误:

postgresql_1  | nami    INFO  Initializing postgresql
postgresql_1  | postgre INFO  ==> No injected postgresql.conf file found. 
Creating default postgresql.conf file...
postgresql_1  | postgre INFO  ==> No injected pg_hba.conf file found. Creating default pg_hba.conf file...
postgresql_1  | postgre INFO  ==> Deploying PostgreSQL from scratch...
postgresql_1  | postgre INFO  ==> Creating database mydatabase...
postgresql_1  | postgre INFO  ==> Creating user "someuser"...
postgresql_1  | postgre INFO  ==> Granting access to "someuser" to the database mydatabase...
postgresql_1  | postgre INFO  ==> Configuring PostgreSQL...
postgresql_1  | postgre INFO  ==> Configuring replication parameters...
postgresql_1  | postgre INFO  ==> Configuring permissions for config files...
postgresql_1  | postgre INFO 
postgresql_1  | postgre INFO  
########################################################################
postgresql_1  | postgre INFO   Installation parameters for postgresql:
postgresql_1  | postgre INFO     User: someuser
postgresql_1  | postgre INFO     Password: ***************
postgresql_1  | postgre INFO     Database: mydatabase
postgresql_1  | postgre INFO   (Passwords are not shown for security reasons)
postgresql_1  | postgre INFO  
########################################################################
postgresql_1  | postgre INFO 
postgresql_1  | nami    INFO  postgresql successfully initialized
postgresql_1  | INFO  ==> Starting postgresql... 
postgresql_1  | 2019-04-15 09:31:18.582 GMT [125] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgresql_1  | 2019-04-15 09:31:18.583 GMT [125] LOG:  listening on IPv6 address "::", port 5432
postgresql_1  | 2019-04-15 09:31:18.587 GMT [125] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
postgresql_1  | 2019-04-15 09:31:18.599 GMT [132] LOG:  database system was shut down at 2019-04-15 09:31:18 GMT
postgresql_1  | 2019-04-15 09:31:18.603 GMT [125] LOG:  database system is ready to accept connections
postgresql_1  | 2019-04-15 09:31:24.414 GMT [139] FATAL:  password authentication failed for user "postgres"
postgresql_1  | 2019-04-15 09:31:24.414 GMT [139] DETAIL:  User "postgres" has no password assigned.
postgresql_1  |         Connection matched pg_hba.conf line 95: "host     all             all             0.0.0.0/0               md5"
postgresql_1  | 2019-04-15 09:31:27.492 GMT [140] FATAL:  password authentication failed for user "postgres"
postgresql_1  | 2019-04-15 09:31:27.492 GMT [140] DETAIL:  User "postgres" has no password assigned.

标签: postgresqldockerdocker-compose

解决方案


如果您检查 docker 映像的文档(https://hub.docker.com/r/bitnami/postgresql),它会说当您设置POSTGRESQL_USERNAMEpostgres 用户时不会分配密码并且您将无法使用它登录到数据库。

使用您指定的用户。


推荐阅读