0

I use docker to run a Postgres database container. My command to start it is:

docker run --name postgres-me -e POSTGRES_PASSWORD=password -d -p 5432:5432 postgres:alpine

Then it is up and running:

~ $ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
b662971d9b54        postgres:alpine     "docker-entrypoint.s…"   6 seconds ago       Up 3 seconds        0.0.0.0:5432->5432/tcp   postgres-me

Then I try to access the container by:

~ $ docker exec -it b662971d9b54 bin/bash
bash-5.0# psql
psql: error: could not connect to server: FATAL:  role "root" does not exist

As you can see above, after I go into the container, then I tried command psql, but I got error could not connect to server: FATAL: role "root" does not exist

How to get rid of this error?

1 Answer 1

2

You need to provide username as well. Try this : psql -U <username>

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

2 Comments

What username should I use?
You can get the username via this command : docker inspect <postgres-container-id> --format '{{.Config.User}}'.

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.