Docker : Postgres doesn't respond to outside request
franckleveque opened this issue · 1 comments
Hi,
Not sure if it is a bug or an intended behavior. I also didn't find any mention on port forwarding for the container in the documentation.
However, I'm currently trying to set a postgres container for development purpose but I'm unable to connect to it using the host machine (I have tried DBEaver with the jdbc postgres driver, and a .Net program using Npgsql). I get the following error :
On DBEaver : FATAL: authentification par mot de passe �chou�e pour l'utilisateur � postgres �
On C# :
Npgsql.PostgresException
HResult=0x80004005
Message=28P01: authentification par mot de passe �chou�e pour l'utilisateur � postgres �
Source=Npgsql
For C#, I used the following connection string : "Host=localhost;Username=postgres;Password=mysecretpassword;Database=postgres"
I used the following command to create the container :
docker run --name some-postgres -v ./postgres_data:/var/lib/postgresql/data -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -v ./script:/docker-entrypoint-initdb.d -d postgres:16-alpine
This command forward the internal port 5432 of the docker container to the 5432 port of the host.
also tried with adding -e POSTGRES_USER postgres and --network host flag without any improvement.
Contacting the server from the container itself using :
docker exec -it some-postgres psql -U postgres
works correctly
So far I'm suspecting something related to the user password as I can connect through the container without providing a password and I have a failed password authentication for user postgres in both my tests on the host but I'm not sure of what exactly the issue is.
This repository contains the source for Docker Official Image (DOI) documentation and is not a general resource for running PostgreSQL or Docker.
You can ask for help in the Docker Community Slack. If you are not already a member of the Docker Community Slack, you can use this link to join. You can find more support options at Docker Support.
You can file bugs you have found in the postgres
DOI in its repository: https://github.com/docker-library/postgres
When you do ask for help, it would help to include the exact errors displayed in the output of the commands you are running and the logs from the postgres
container.
Good luck!