skip to Main Content

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


  1. can you ping to your pg server?
    if yes, check pg_hba.conf first at pg server side.

    Login or Signup to reply.
  2. You may be able to add --network=host to your docker run command.

    https://docs.docker.com/reference/cli/docker/container/run/#network

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search