How to connect from docker-compose to Host PostgreSQL?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 19:58:33

Updated Apri, 2018

According to the document, from version 18.03 onwards, using host.docker.internal as DNS works for me, without specifying neither --net=host or network_mode: "host"

This would have worked if you were on linux OS. But this won't work on Mac or Windows. The thing is that when you use --net=host, you still are not on host network. That is the limitation of how docker for windows work

Instead of localhost you need to use docker.for.win.localhost as the host. This is a special DNS name which is available on Docker for Windows when you want to refer to the host localhost

Cautionary note: using the --net=host, or network_mode: "host" will prevent your container from registering with Eureka and will break any kind of API gateway you've got unless they all run on the same network.

1) ensure that your postgresql instance is listening to all addresses and not only localhost.

In postgresql.conf set listen_addresses as follows:

listen_addresses='*'

2) you are trying to connect from your container to localhost:5432 . That is NOT your host's IP address, but the address of your container's loopback device. You need to use your docker bridge IP address instead.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!