首页 > 解决方案 > Dockerising Elixir/Phoenix 应用程序:(Postgrex.Error) FATAL 28P01 (invalid_password) 用户“postgres”的密码验证失败

问题描述

我有一个 Elixir/Phoenix 应用程序,我一直在本地工作,由 PostgreSQL 支持。当我通过终端运行时,一切正常mix phx.server

我现在正在尝试 dockerise 应用程序,以便我可以部署到 AWS。我正在关注使用 Distillery使用 Docker 部署文档。

我已经从该页面逐字复制了所有设置,因此在我使用相同的配置时,请随意查看这些配置。

当我尝试运行时docker-compose up,出现以下错误:

...

db_1   |    Connection matched pg_hba.conf line 95: "host all all all md5"
web_1  | 12:05:31.631 [error] Postgrex.Protocol (#PID<0.1879.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
db_1   | 2020-04-14 12:05:32.093 UTC [54] FATAL:  password authentication failed for user "postgres"
db_1   | 2020-04-14 12:05:32.093 UTC [54] DETAIL:  Password does not match for user "postgres".
db_1   |    Connection matched pg_hba.conf line 95: "host all all all md5"
web_1  | 12:05:32.094 [error] Postgrex.Protocol (#PID<0.1877.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
db_1   | 2020-04-14 12:05:32.295 UTC [55] FATAL:  password authentication failed for user "postgres"
db_1   | 2020-04-14 12:05:32.295 UTC [55] DETAIL:  Password does not match for user "postgres".
db_1   |    Connection matched pg_hba.conf line 95: "host all all all md5"
web_1  | 12:05:32.296 [error] Postgrex.Protocol (#PID<0.1870.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
db_1   | 2020-04-14 12:05:32.640 UTC [56] FATAL:  password authentication failed for user "postgres"
db_1   | 2020-04-14 12:05:32.640 UTC [56] DETAIL:  Password does not match for user "postgres".
db_1   |    Connection matched pg_hba.conf line 95: "host all all all md5"
web_1  | 12:05:32.641 [error] Postgrex.Protocol (#PID<0.1880.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
db_1   | 2020-04-14 12:05:33.150 UTC [57] FATAL:  password authentication failed for user "postgres"
db_1   | 2020-04-14 12:05:33.150 UTC [57] DETAIL:  Password does not match for user "postgres".
db_1   |    Connection matched pg_hba.conf line 95: "host all all all md5"
web_1  | 12:05:33.151 [error] Postgrex.Protocol (#PID<0.1875.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
...

这可能是一个相当简单的问题要解决,但我没有做太多的数据库管理。我的猜测是我需要更改config/docker.env文件中的某些内容(来自上面的链接)。

如果我没记错的话,postgres用户的默认密码是空白的。但我不确定如何使用该docker.env文件设置空白密码。理想情况下,我想在 docker 构建期间自己设置用户名和密码,这样我就知道创建了什么用户等(假设这是明智的做法)。

任何提示将不胜感激。

标签: postgresqldockerdocker-composeelixirphoenix-framework

解决方案


您发布的链接使用标准Postgres Docker Image

您可以通过设置Environment Variables来扩展/配置此图像。

最突出的:

  • POSTGRES_PASSWORD
  • POSTGRES_USER
  • POSTGRES_DB

您发布的config/docker.env 内容还使用环境变量——但仅用于配置应用程序——而不是 Postgres 图像。此设置静默假定默认值来自postgres:10-alpine.

您可以添加 Postgres Image 理解的环境变量并使用现有的应用程序配置。

为了使它与自选的用户名和密码一起工作。这应该足够了:

config/docker.env

# ...
DATABASE_USER=dbsuperuser
DATABASE_PASS=dbsuperuserpassword
POSTGRES_PASSWORD=dbsuperuserpassword
POSTGRES_USER=dbsuperuser
# ...

警告:使用环境变量配置的用户和密码是超级用户。这不应该是应用程序连接到数据库的用户——尽管本教程对此进行了宣传。


推荐阅读