[英]Can't connect to my docker host postgresql database from a container
If I do ifconfig
, docker0
ip is 172.17.0.1
and when I run my containerized app and then docker network inspect bridge
myapp ip is 172.17.0.2
, they are on the same network I suppose. 如果我执行
ifconfig
,则docker0
ip是172.17.0.1
,当我运行容器化的应用程序时,然后docker network inspect bridge
myapp ip是172.17.0.2
,它们位于我想的同一网络上。
But inside myapp I am trying to connect to my docker host's postgresql database, I provide 172.17.0.1:5432
to my ORM but it throws an error connect ECONNREFUSED 172.17.0.1:5432
. 但是在myapp内部,我试图连接到docker主机的postgresql数据库,我向ORM提供了
172.17.0.1:5432
,但connect ECONNREFUSED 172.17.0.1:5432
却引发错误。
What is the problem ? 问题是什么 ?
check your pg_hba.conf file in the data directory of your postgres instance. 检查postgres实例的数据目录中的pg_hba.conf文件。 In this file you configure which users are allowed to authenticate through which network.
在此文件中,配置允许哪些用户通过哪个网络进行身份验证。 Make sure your postgres instance is accepting connections from the docker0 network by adding the following line:
通过添加以下行,确保您的postgres实例正在接受来自docker0网络的连接:
host all all 172.17.0.0/24 md5
in this line you could adjust the second 'all' to specify a certain user. 在这一行中,您可以调整第二个“全部”以指定某个用户。
我忘记在postgresql.conf
添加listen_addresses="*"
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.