1

I run

docker pull postgres

docker run -d -p 5432:5432 --memory="1g" --name some-postgres -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e PGDATA=/var/lib/postgresql/data/pgdata -v D:\docker_mount:/var/lib/postgresql/data postgres

Image: https://hub.docker.com/_/postgres

In Docker postgreSQL container CLI, I tried

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

enter image description here

enter image description here

Docker PostgreSQL 14: How to run psql?

Vy Do
  • 46,709
  • 59
  • 215
  • 313
  • 1
    The answer is actually about halfway down on the page you linked. – mustaccio Dec 19 '21 at 13:35
  • Unless you add a proper switch `psql -U postgres`, psql will try to connect as the current system user, which happens to be `root`. As @mustaccio pointed out, the page you linked already shows the full command: `docker run -it --rm --network some-network postgres psql -h some-postgres -U postgres` where you can see the use of `-U postgres` which is shorthand for `--username=postgres` – Zegarek Dec 19 '21 at 14:23

0 Answers0