Docker – Postgres and pgAdmin 4 : Connection refused

  1. Pgadmin fails to connect to localhost, but psql works from outside docker.
  2. both pgadmin & Postgres are running as Containers

Although you haven’t indicated if you are doing so, ideally both containers could be part of a custom bridge network for automatic DNS resolution.

If not added explicitly they will be part of the default bridge network.

To find out the networks created in your docker runtime, type: $ docker network ls

Some networks will be listed in the console, maybe you’ll find a [name]_default it should be your network.

Execute docker network inspect [name]_default it’ll show up a bunch of information, for us the most important is IPv4Address, something like this: "7c3cd7532ab8aacc70830afb74adad7296d9c8ddd725c498af2d7ee2d2c2aadd": { "Name": "intime_postegres_1", "EndpointID": "56a9cb574469f22259497b72719f9f4a3e555b09f95058fcf389ef5287381f28", "MacAddress": "02:42:ac:12:00:02", "IPv4Address": "172.18.0.2/16", "IPv6Address": "" }

Instead of using localhost for the server name/ip in the pgAdmin new server dialog, connect to the postgres instance’s “IPv4Address”.

In my case connecting at 172.18.0.2:5432, worked like a charm. 

Source – https://stackoverflow.com/questions/53610385/docker-postgres-and-pgadmin-4-connection-refused

Leave a Comment

Your email address will not be published. Required fields are marked *