简体   繁体   中英

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.

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 .

What is the problem ?

check your pg_hba.conf file in the data directory of your postgres instance. 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:

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="*" ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM