0

I'm trying to connect and run postgres container with psql:

docker pull postgres

docker run -e  POSTGRES_PASSWORD=password -d postgres

C:\Program Files\PostgreSQL\13\bin>psql <myUserName>
Password for user <myUserName>:

at this point when I type the password, it shows the error

psql: error: FATAL:  password authentication failed for user "<myUserName>"

What am I doing wrong?

4
  • In my hands, your 2nd command never gives back a command prompt. So where is your 3rd command getting executed from? Commented Aug 9, 2021 at 14:08
  • You don't create a database user named "<myUserName>". The password you told it to use got assigned to user named "postgres". Commented Aug 9, 2021 at 14:11
  • Do you have running postgresql service on your machine ? Commented Aug 9, 2021 at 14:34
  • @Amin yes, this command "docker run -e POSTGRES_PASSWORD=password -d postgres" just starts it. We can confirm it by running "docker ps", which returns: "c792cdeae2d4 postgres "docker-entrypoint.s…" 14 seconds ago Up 13 seconds 5432/tcp boring_satoshi" Commented Aug 10, 2021 at 6:53

1 Answer 1

1

When you use docker run -e POSTGRES_PASSWORD=password -d postgres, the POSTGRES_PASSWORD would be set for user postgres as default. you can specify your user with POSTGRES_USER environment.

Second thing is that when you run a postgresql container and don't bind any ports for that, you can't connect to that container from outside. So you won't being able to connect to your container with pure pqsl command. Here you have 3 way to connect to your container:

1- Use docker run -e POSTGRES_PASSWORD=password -p 5432:5432 -d postgres to run container, then connect to it with psql -h <YOUR_IP> -p 5432 -U <USERNAME>

2- Get your container ip with docker inspect <CONTAINER_NAME> command, then connect to it with psql -h <CONTAINER_IP> -U <USERNAME>

3- Use psql inside your container with docker exec -it <CONTAINER_NAME> psql -U <USERNAME>

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

2 Comments

It does not help, I'm still getting this error message: "psql: error: could not connect to server: Connection timed out (0x0000274C/10060) Is the server running on host "172.17.0.2" and accepting TCP/IP connections on port 5432?"
Which option did you take ? @Jaana

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.