Docker Community Forums

Share and learn in the Docker community.

[POSTGRES - SOLVED] Fail to connect Postgresql container

docker

(Qvdp) #1

Hi,

I’m very new to docker. I’ve been searching for my answer but all i found did not worked.

I have installed docker on my local server (Synology) and ran two linked containers - one for nodejs, the other for postgresql.

I can access in my terminal, with my local IP or my public IP to the postgresql container and create a new db and so on… by accessing my server in ssh, run an instance in my docker container and log with psql.

Now, i would like to access my database with an app like PGadmin or Tableplus on my laptop but it doesn’t work. I’have published the container on my 5431 port and set a POSTGRES_PASSWORD in my environment but I always get this message when i try to connect :

“server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.”

To be honest i don’t know which IP adress i should use so tried with all IP i know. When i type docker ps it returns :

0.0.0.0:5431->5431/tcp

When I type docker inspect my-postgres-container, it returns :

“5431/tcp”: [
{
“HostIp”: “0.0.0.0”,
“HostPort”: “5431”
}
]
(…)
“Gateway”: “172.17.0.1”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“IPAddress”: “172.17.0.3”,

Why it doesn’t work ?

Thank you for you help


(Sam) #2

ok… this means the container port 5431 is mapped to the host port 5431.

so that means some application on another machine (your laptop) should be able to access via
server_address:5431
this

“IPAddress”: “172.17.0.3”,

means that the container ip address is set to 172.17.0.3, but it can only be reached directly from the machine where docker run was issued.

see here for solving the connection reset problem

postgres, mysql and mongo all default to ONLY allow connections from the SAME MACHINE


(Qvdp) #3

EDIT : Thank you for your answer @sdetweil. I followed the instructions of this topic. I entered in the conf file but it was already written that all IP (v4) were listned (i had to install nano also) :

listen_adress = ‘*’

I also uncomment the default port and change it for 5431. Now it’s fully working, i use this adress :

my.server.adress : 5431

I’ve also been able to access my postgres container by creating a new container with the pgadmin’s image on the same machine and in the same docker network.

Thank you !


(Sam) #4

what is that address? it is not the container

and it is not the docker host machine ip address


(Qvdp) #5

Just edited my message :D. I made a mistake in my local adress in Tableplus, now it’s working. :ok_hand:
And it also working outside of my network, that’s perfect. I can use Table Plus and connect to my database from everywhere with my laptop.