如何解决将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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。