简体   繁体   English

无法从容器连接到我的Docker主机Postgresql数据库

[英]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.

相关问题 Docker 容器无法从主机访问映射目录 - Docker container can't access mapped directory from host Docker 容器无法连接到 Redis - Docker container can't connect to Redis 如何从 windows 主机访问我的设备到 docker linux 容器? - How can I access my device from a windows host to a docker linux container? 如何使Postgresql数据库可从Postgres Docker容器外部连接? - How to make postgresql database connectable from outside of the postgres docker container? 如何从docker容器rsync到我的主机 - how to rsync from a docker container to my host computer 无法从同一局域网中的另一台主机ping Docker容器 - Can not ping docker container from another host which is in the same LAN 无法连接到Digitalocean上的docker-machine容器 - Can't connect to docker-machine container on digitalocean 无法连接到 docker 容器外的 oracle:12.1.0.2 - Can't connect to oracle:12.1.0.2 outside docker container Docker无法使用代理连接到Internet - Docker can't connect to the internet from with proxy 我可以在与要运行diff的容器相同的主机上运行docker diff吗? - Can I run docker diff from a container on the same host as the container I want to run the diff on?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM