Home > Software design >  POSTGRES_DB and POSTGRES_USER don't work in Docker run
POSTGRES_DB and POSTGRES_USER don't work in Docker run

Time:02-03

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?

CodePudding user response:

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

docker exec -it psql-instance psql -U root mydb
  • Related