# \[POSTGRES - SOLVED\] Fail to connect Postgresql container

**URL:** <https://forums.docker.com/t/postgres-solved-fail-to-connect-postgresql-container/46924>\
**Category:** General\
**Tags:** docker\
**Created:** [February 25, 2018, 10:49am UTC](https://forums.docker.com/t/postgres-solved-fail-to-connect-postgresql-container/46924 "2018-02-25T10:49:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![qvdp](https://avatars.discourse-cdn.com/v4/letter/q/258eb7/32.png) [@qvdp](https://forums.docker.com/u/qvdp)\
**Post date:** [February 25, 2018, 10:49am UTC](https://forums.docker.com/t/postgres-solved-fail-to-connect-postgresql-container/46924/1 "2018-02-25T10:49:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sdetweil](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@sdetweil](https://forums.docker.com/u/sdetweil)\
**Post date:** [February 25, 2018, 1:33pm UTC](https://forums.docker.com/t/postgres-solved-fail-to-connect-postgresql-container/46924/2 "2018-02-25T13:33:28Z")

</div>

> [@qvdp](#):
>
> 0.0.0.0:5431-\>5431/tcp

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

```auto
“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

> <https://stackoverflow.com/questions/15934364/psql-server-closed-the-connection-unexepectedly>

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

---

<div class="post-metadata">

**Author:** ![qvdp](https://avatars.discourse-cdn.com/v4/letter/q/258eb7/32.png) [@qvdp](https://forums.docker.com/u/qvdp)\
**Post date:** [February 25, 2018, 5:02pm UTC](https://forums.docker.com/t/postgres-solved-fail-to-connect-postgresql-container/46924/3 "2018-02-25T17:02:51Z")

</div>

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 !

---

<div class="post-metadata">

**Author:** ![sdetweil](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@sdetweil](https://forums.docker.com/u/sdetweil)\
**Post date:** [February 25, 2018, 5:04pm UTC](https://forums.docker.com/t/postgres-solved-fail-to-connect-postgresql-container/46924/4 "2018-02-25T17:04:38Z")

</div>

> [@qvdp](#):
>
> local.server.machine.adress

what is that address? it is not the container

and it is not the docker host machine ip address

---

<div class="post-metadata">

**Author:** ![qvdp](https://avatars.discourse-cdn.com/v4/letter/q/258eb7/32.png) [@qvdp](https://forums.docker.com/u/qvdp)\
**Post date:** [February 25, 2018, 5:08pm UTC](https://forums.docker.com/t/postgres-solved-fail-to-connect-postgresql-container/46924/5 "2018-02-25T17:08:03Z")

</div>

Just edited my message :D. I made a mistake in my local adress in Tableplus, now it’s working. 👌  
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.

---

<div class="post-metadata">

**Author:** ![enderandpeter](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/enderandpeter/32/12751_2.png) [@enderandpeter](https://forums.docker.com/u/enderandpeter)\
**Post date:** [December 20, 2020, 3:53am UTC](https://forums.docker.com/t/postgres-solved-fail-to-connect-postgresql-container/46924/6 "2020-12-20T03:53:30Z")

</div>

Port mappings, baby!

---

<div class="post-metadata">

**Author:** ![08455](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/08455/32/37635_2.png) [@08455](https://forums.docker.com/u/08455)\
**Post date:** [November 24, 2022, 10:52am UTC](https://forums.docker.com/t/postgres-solved-fail-to-connect-postgresql-container/46924/7 "2022-11-24T10:52:52Z")

</div>

@qvdp Hello, on which file did you find this line my.server.adress : 5431?

is it on pg\_hba.conf or postgressql.conf ?
