Can’t connect to database via pgcli

Hey guys,

I hope this is the right sub.

I created a db with the following command:

docker run -it \
  -e POSTGRES_USER="root" \
  -e POSTGRES_PASSWORD="root" \
  -e POSTGRES_DB="ny_taxi" \
  -v $(pwd)/ny_taxi_postgres_data:/var/lib/postgresql/data \
  -p 5432:5432 \
  postgres:13

This is working fine. Now I want to access the database via pgcli and I get the following error:

❯ pgcli -h localhost -p 5432 -U root -d ny_taxi
connection failed: :1), port 5432 failed: FATAL:  role "root" does not exist

But when I run

docker exec -it <container_name> /bin/bash 

and then

psql -h localhost -d ny_taxi -U root

I get access:

❯ docker exec -it focused_blackwell /bin/bash
root@14ee944f84dc:/# psql -h localhost -d ny_taxi -U root
psql (13.9 (Debian 13.9-1.pgdg110+1))
Type "help" for help.

ny_taxi=#

Can anybody help me?
Thank you!

1 Like