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:
psql: The server closed the connection unexpectedly
This probably means that the server has terminated abnormally
before or while processing your inquiry.
CodePudding user response:
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.