Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot connect to Postgres running in Docker from PGAdmin running on Windows Host

I have read all the questions on this, like this one, but it does not help.

Host: Windows 10, running VirtualBox and PgAdmin.

I have setup Docker correctly and run a few containers without issue. Now I tried to setup Postgres. I tried two:

1 https://hub.docker.com/r/paintedfox/postgresql/

2 https://hub.docker.com/_/postgres/

And both have the same issue. When I try to connect from PgAdmin, it says the server does not listen.

When I run docker inspect postgres I see

"NetworkSettings": { "Bridge": "", "SandboxID": "6ad76f4d61017c44f814c5ec7ab9081a650d925a46c2b69902c4f0e5209076ce", "HairpinMode": false, "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "Ports": { "5432/tcp": null }, "SandboxKey": "/var/run/docker/netns/6ad76f4d6101", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null, "EndpointID": "3f14630554c972ac875cbb384725c6970d1d4d5acfba7cbc05e416b5b22f0056", "Gateway": "172.17.0.1", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "IPAddress": "172.17.0.2",

I have tried that IP address as the host in PGAdmin.

I have tried setting the container with -p 5432:5432 and connecting as 127.0.0.1:5432.

I have tried setting port forwarding in VirtualBox for the container.

I also tried the machine host, as shown in Kitematic: 192.168.99.100

like image 949
rmcsharry Avatar asked Feb 08 '16 10:02

rmcsharry


People also ask

How do I run PostgreSQL and pgAdmin in Docker?

Fill the port value as 5432 that runs the Docker PostgreSQL Container and provide the name of the database as postgres. Then, fill the username and password fields with the credentials you created while running the PGAdmin container. After providing all required details, click on the “Save” button.

How do I connect pgAdmin to Docker container?

PgAdmin Docker Setup: Docker Images and Docker Compose. PgAdmin Docker Setup: Creating The Docker Compose File. PgAdmin Docker Setup: Verification of Docker Connection. PgAdmin Docker Setup: Set up the PostgreSQL Connection.

Can't connect to server connection refused pgAdmin?

If pgAdmin displays this message, there are two possible reasons for this: the database server isn't running - simply start it. the server isn't configured to accept TCP/IP requests on the address shown.


2 Answers

I finally noticed that in Kitematc in the IP & Ports section on the Home tab that the ACCESS URL was not set.

Under Docker Port it shows '5432/tcp'

So I clicked the IP address next to that and set it and now it shows:

192.168.99.100:32768

I put that IP and port into PGAdmin and it can now connect to the container.

FYI that IP is the same IP returned by:

docker-machine ip default
like image 66
rmcsharry Avatar answered Nov 15 '22 15:11

rmcsharry


If you run your container from command-line alter your run-command like this:

docker run -p 32768:5432 my-postgres

Now you can connect to your postgres via <mapped-ip>:32768 (in my case the mapped IP was 192.168.99.100)

like image 42
Jaroslav Záruba Avatar answered Nov 15 '22 16:11

Jaroslav Záruba