Failed login to Docker postgres image via localhost with published port, but accessible by external IP

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 trust
host all all ::1/128 trust

The host machine is Windows 7.

Are you using Docker Toolbox or Docker Machine? You will always have to use the docker-machine ip address (; localhost will never work.