2

I am trying to connect to a locally running postgres on docker. I am running the basic tutorial initialization:

docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres

when I try: pgcli -h localhost -U postgres postgres I get password denied. I have also tried with pguser. I have also tried setting the username as well with the same result.

When I try with a generic database application, DBeaver, same result password denied. I have tried going in to the running container and resetting the password as well: docker exec -it <hash> bash and then manually setting the password again to something simple.

2
  • You have to forward a port from local machine into the container and then connect to the forwarded port. If you are using the default port then you'll also need to stop the local postgres server only if installed, otherwise no need. Commented Dec 25, 2020 at 17:50
  • "password denied" is not a wording PostgreSQL would use. Please quote the exact error message. Commented Dec 25, 2020 at 18:08

3 Answers 3

1

I was getting a similar error with port 5432 (default) and I had a local postgres installation too, which is creating the problem. To avoid the two instances fighting for same port, two things can be done.

  1. Stop instance of local postgres
  2. In docker container postgres path, open postgresql.conf and change default port.
Sign up to request clarification or add additional context in comments.

Comments

1

I was having trouble connecting to my PostgreSQL database in a Docker container. After troubleshooting, I realized the issue was a port conflict. Switching the mapped port from 5432 to 5433 in my Docker Compose configuration resolved the problem.

Please refer: https://forums.docker.com/t/cant-connect-to-postgres-through-docker/120051/9

Comments

0

I faintly remember postgresql to a) have a different password for a postgresql account than the one you have to set for the linux user account and b) having to activate logging in with a username and password somewhere in the config

Hope this helps, just something off the top of my head

1 Comment

no such luck as I tried docker run --name some-postgres -e POSTGRES_USER=someuser -e POSTGRES_PASSWORD=mysecretpassword -d postgres and same result with pgcli -h localhost -p 5432 -U someuser postgres

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.