在 EC2 上使用 docker-compose up 对用户“postgres”进行密码身份验证失败

Edo*_*ard 5 postgresql amazon-ec2 docker docker-compose docker-machine

在由 docker-machine 创建的 EC2 linux 服务器上,当我通过docker-compose up启动 docker postgres:10.6,出现以下循环错误:

FATAL:  password authentication failed for user "postgres"
DETAIL:  Password does not match for user "postgres".
Connection matched pg_hba.conf line 95: "host all all all md5"
Run Code Online (Sandbox Code Playgroud)

如果我手动启动容器,我就不会出现这些错误 => docker run -e POSTGRES_PASSWORD=myPassword postgres:10.6

我的本地 docker 中没有这些错误。

我的 docker-compose :

FATAL:  password authentication failed for user "postgres"
DETAIL:  Password does not match for user "postgres".
Connection matched pg_hba.conf line 95: "host all all all md5"
Run Code Online (Sandbox Code Playgroud)

有谁知道如何解决这一问题?

Aks*_*hah 14

这可能是因为卷(或绑定安装目录)在您第一次启动后已经初始化。postgres 用户和数据库创建仅在第一次启动时发生(即,/var/lib/postgresql/data 不得已包含数据库文件)。尝试运行:

  • docker-compose rm -fv postgres 删除任何容器或卷(特别是)。
  • docker-compose up -d 启动你的容器。

  • 我必须运行“dockervolumels”来查找卷的名称,然后运行“dockervolumerm<volume_name>”。然后我可以重新初始化 postgres 卷 (2认同)