Closed icleary5 closed 9 months ago
Hmm, something weird is happening here, but I'm not sure where! I tried reproducing with a --network=host
container (so I don't need psql
on my host, which is something I do not have :sweat_smile:), and I ran into it defaulting to the unix socket (somewhat expected) but adding -h
made it work fine:
$ docker pull postgres
Using default tag: latest
latest: Pulling from library/postgres
Digest: sha256:31c9342603866f29206a06b77c8fed48b3c3f70d710a4be4e8216b134f92d0df
Status: Image is up to date for postgres:latest
docker.io/library/postgres:latest
$ docker run -d -e POSTGRES_PASSWORD=pwd -p 5433:5432 postgres
4ec13f8afff9df1d1f76ca5db5451061d97edb270f4a9f50a5d1fe86b7b430a2
$ docker logs --tail=2 4ec13f8afff9df1d1f76ca5db5451061d97edb270f4a9f50a5d1fe86b7b430a2
2023-06-05 18:44:09.269 UTC [62] LOG: database system was shut down at 2023-06-05 18:44:09 UTC
2023-06-05 18:44:09.274 UTC [1] LOG: database system is ready to accept connections
$ docker run -it --rm --network host --env PGPASSWORD=pwd postgres psql -p 5433 -U postgres
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5433" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
$ docker run -it --rm --network host --env PGPASSWORD=pwd postgres psql -h 127.0.0.1 -p 5433 -U postgres
psql (15.3 (Debian 15.3-1.pgdg110+1))
Type "help" for help.
postgres=#
Thanks for trying this @tianon, but I don't think you have reproduced the issue.
Yep, that's exactly what I'm saying -- I've reproduced your test case, but not the issue. :sweat_smile:
(At this point, my best guess is something related to Windows or Docker Desktop for Windows, but it's hard to say for sure.)
I am also unable to reproduce. š This is using psql
from a WSL2 Debian instance with the container running in Docker Desktop:
$ docker pull postgres
Using default tag: latest
latest: Pulling from library/postgres
...
Digest: sha256:31c9342603866f29206a06b77c8fed48b3c3f70d710a4be4e8216b134f92d0df
Status: Downloaded newer image for postgres:latest
docker.io/library/postgres:latest
$ docker run -d -e POSTGRES_PASSWORD=pwd -p 5433:5432 postgres
a02b8eeb5dac394ae336bacb6a275c7b53b41860dc41b1d1e32607a95aef17f0
$ docker logs --tail=2 a02b8eeb5dac394ae336bacb6a275c7b53b41860dc41b1d1e32607a95aef17f0
2023-06-05 20:55:45.029 UTC [62] LOG: database system was shut down at 2023-06-05 20:55:44 UTC
2023-06-05 20:55:45.032 UTC [1] LOG: database system is ready to accept connections
$ PGPASSWORD=pwd psql -h 127.0.0.1 -p5433 -U postgres
psql (13.11 (Debian 13.11-0+deb11u1), server 15.3 (Debian 15.3-1.pgdg110+1))
WARNING: psql major version 13, server major version 15.
Some psql features might not work.
Type "help" for help.
postgres=#
\q
I also installed the client binaries in Windows and those work both from the "SQL shell (pqsl)" and via running the bin\psql
binary in the installation directory from powershell:
# "SQL Shell (psql)
Server [localhost]:
Database [postgres]:
Port [5432]: 5433
Username [postgres]:
Password for user postgres:
psql (15.3)
WARNING: Console code page (437) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
Type "help" for help.
postgres=#
PS C:\Program Files\PostgreSQL\15> .\bin\psql.exe -p 5433 -U postgres
Password for user postgres:
psql (15.3)
WARNING: Console code page (437) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
Type "help" for help.
postgres=#
š
Have you tried adding -h 127.0.0.1
to your psql
line? Is there a conflicting PostgreSQL running in Windows that is being connected to instead?
Have you checked your hba.conf ?
https://www.postgresql.org/docs/current/auth-pg-hba-conf.html
i do not know what is the default contend of it .. but probably you have uncommon network setup / network range and simply this basic protection layer blocks your request to connect ?
I am trying to make a docker-compose.yml that will publish port "5433:5432" so I can access it with psql on port 5433 on localhost. I set the POSTGRES_PASSWORD, but password authentication fails. Here is my journey:
Note: Between each test, I am stopping and removing all containers using
docker compose down
ordocker ps -qa | xargs docker stop | xargs docker rm
, depending on the situation.I started with this compose file:
I tried to connect with psql:
Hmm... I wonder if it works with the default port:
I tried connecting to it:
Ok that worked! So the only difference is the published port number. What if I do this comparison outside of a compose file?
$ docker run -d -e POSTGRES_PASSWORD=pwd -p 5432:5432 postgres
As expected, connecting to 5432 works just fine. No surprises here:
Now what happens if I change the published port to 5433?
$ docker run -d -e POSTGRES_PASSWORD=pwd -p 5433:5432 postgres
Oh look! It fails here too:
So by this point I've established that in both contexts -
docker compose
anddocker run
- the failure depends only on the published port number. I thought I'd experiment with Docker's confusingly documented "expose" concept, which isn't supposed to do anything in this context, but I thought I'd give it a try.$ docker run -d -e POSTGRES_PASSWORD=pwd -p 5433:5432 --expose 5433 postgres
And sure enough, it still doesn't work:
I dunno, maybe it will do something in compose?
Nope!
My understanding is that this publishing a postgres container's port to something other than the default is supposed to work. It's clear that the postgres container is listening on the published port. It's just rejecting the password if and only if the published port varies from the default.
Note: I am running Windows 11 Pro on an HP EliteBook 840 G6. I'm using the latest version of Docker Desktop and the latest version of the postgres image (15.3-1.pgdg110+1). I run my docker commands on Git Bash on Debian. Here is the system info for my Docker installation: