Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cannot connect to database on Docker

I have created database on docker:
docker run --name database -e POSTGRES_PASSWORD=password -d -p 5436:5436 postgres
Created some database inside:

createdb database

Also created superuser. Now I am trying to connect from localhost:

psql -h localhost -p 5436 -U postgres

After that I get following error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 psql: The server closed the connection unexpectedly
        This probably means that the server has terminated abnormally
        before or while processing your inquiry.

Ports are connected:
enter image description here

>Solution :

In your case, you are trying to expose 5436 and map with your host port 5436, but that might need to use -p 5436:5432 because Postgres uses port 5432 as the default port.

docker run --name database -e POSTGRES_PASSWORD=password -d -p 5436:5432 postgres

There is some description from Container networking

-p 8080:80:Map TCP port 80 in the container to port 8080 on the Docker host.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading