2

So I am running the following command:

docker run --name psql-instance -d -p 5432:5432 -e POSTGRES_DB=mydb -e POSTGRES_USER=root -e POSTGRES_PASSWORD=pass postgres

This creates the container.

However when I run:

docker exec -it psql-instance psql -U root

I get the following error:

psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  database "root" does not exist

I've seen many similar questions and they all say its docker-compose causing the error for them and that docker run works fine but for me, docker run doesn't work.

How can I fix this?

1 Answer 1

2

You need to tell psql to connect to the mydb database like this

docker exec -it psql-instance psql -U root mydb
Sign up to request clarification or add additional context in comments.

Comments

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.