1

I'm trying a simple setup with a docker postgres image, publishing a port for me to connect from the localhost.

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

I'm able to connect just fine if I specify the docker external IP:

psql -h 192.1469.99.100 -p 5432 -U postgres -d postgres --password

However I get a password authentication failure when trying against localhost:

psql -h localhost -p 5432 -U postgres -d postgres --password
psql: FATAL: password authentication failed for user "postgres"

Do I need to set up some manual port forwarding manually? The weird thing is that it seems to connect to the postgres server just fine, it's just bizarrely telling me the password fails. I've done something wrong with the docker config perhaps?

The pg_hba.conf looks like:

local all all trust
host all all 127.0.0.1/32 trust
host all all ::1/128 trust

The host machine is Windows 7.

2 Answers 2

1
  1. Did you try another port than 5432? Try some free port so that there is no conflict between your local postgre and your docker postgre. To me it looks like your local postgre is having higher prio on localhost:5432, takes the traffic and so you are trying to login to your local postgre instead of your docker postgre, but obv. just a guess.

  2. Did you check if you have this port allowed in the virtual machine or whatever you use for virtualization?

Sign up to request clarification or add additional context in comments.

1 Comment

Did it help @Nathan? If yes then please accept the answer so everybody sees it as solved.
0

The container has its own network and its loopback address does not refer to the host and vice versa.

1 Comment

Right, I'm not expecting anything within the container to refer back to the host. For the vice-versa part, isn't the point of -p 5432:5432 to publish the port for access by any device on the network (including the host machine)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.