将Postgres从本地计算机连接到Docker时,用户的密码身份验证失败

问题描述

我正在使用docker容器将本地计算机上的postgres连接连接到docker,以导入开放的街道地图数据。但是我的用户身份验证失败。

docker run --name "postgis" -p 5432:5432 -d -t kartoza/postgis:11.5-2.8

我的pg_hba.conf文件

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# IPv4 local connections:
host    all             all             172.17.0.1/16            md5
host    all             all             0.0.0.0/0            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost,by a user with the
# replication privilege.
host    replication     all             127.0.0.1/32            md5
host    replication     all             172.17.0.1/16            md5
host    replication     all             ::1/128                 md5

我也更改了md5 to trust,但仍然面临以下问题。

2020-10-14 04:56:53.055 UTC [166] postgres@gis FATAL: password authentication Failed for user "postgres"

2020-10-14 04:56:53.055 UTC [166] postgres@gis DETAIL: User "postgres" has no password assigned.

Connection matched pg_hba.conf line 100: "host all all 172.0.0.0/8 md5"

,我的 postgres版本为11.9,客户端为11.8 ,IP为"IPv4Address": "172.17.0.2/16"

我该如何解决?建议我

解决方法

最初,我在导致此问题的数据库连接字符串中使用了localhost:5432,127.0.0.1:5432 and 172.17.0.1:5432

在连接字符串中使用下面的主机地址后,我的问题已解决

host.docker.internal:5432

postgres://db_user:db_password@host.docker.internal:5432/db

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...