I started to dabble with docker. I have a asp .net core application. I can go to my route /health and see my app can connect to my postgres server fine. But the moment I deploy my application to a container and run it locally, it is unable to connect to that database.
I tried exposing port 5432 in Dockerfile but that didn’t assist in anyway. The error I got is Failed to connect to xx.xx.xx.xxxx:5432
I was wondering if I can get any assistance in how to connect to my remote pg server from my container.
When I telnet from my container, it’s unable to reach the server. But telnet works from from my machine
2
Answers
can you ping to your pg server?
if yes, check pg_hba.conf first at pg server side.
You may be able to add
--network=host
to yourdocker run
command.https://docs.docker.com/reference/cli/docker/container/run/#network