Attempting to connect (with pgAdmin4 or attempting a DB migrate with Prisma) to my PostgreSQL running in docker, however, results in the error message
Error: P1000: Authentication failed against database server at `localhost`, the provided database credentials for `postgres` are not valid.
Please make sure to provide valid database credentials for the database server at `localhost`.
Here are the log message from the docker container pg_container
:
2023-07-10 23:28:55 2023-07-11 03:28:55.532 UTC [84] FATAL: password authentication failed for user "postgres"
2023-07-10 23:28:55 2023-07-11 03:28:55.532 UTC [84] DETAIL: Role "postgres" does not exist.
2023-07-10 23:28:55 Connection matched pg_hba.conf line 100: "host all all all scram-sha-256"
My docker-compose.yml
:
services:
dev-db:
container_name: pg_container
image: postgres:latest
restart: always
ports:
- 5432:5432
environment:
- POSTGRES_USER= postgres
- POSTGRES_PASSWORD= 1234
- POSTGRES_DB= dev
pgadmin:
container_name: pgadmin4_container
image: dpage/pgadmin4
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: admin@admin.com
PGADMIN_DEFAULT_PASSWORD: root
ports:
- "5050:80"
Running docker ps
:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d31b7483c8ad postgres:latest "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 0.0.0.0:5432->5432/tcp pg_container
fa587cd32a04 dpage/pgadmin4 "/entrypoint.sh" 2 minutes ago Up 2 minutes 443/tcp, 0.0.0.0:5050->80/tcp pgadmin4_container
What I've tried:
If you're using the list-of-strings form of environment:
then each item is exactly KEY=value
, with no whitespace. If there is whitespace then it is included in the key and/or value. In your example, the username is postgres
with a leading space, and the database name is similarly dev
with a space.
You can try entering these credentials with the spaces into PGAdmin or Prisma.
In the Compose file, you either need to remove the spaces
environment:
- POSTGRES_USER=postgres
# ^^ no space here
or change to the YAML map syntax, which will more consistently use YAML quoting and escaping rules
environment:
POSTGRES_USER: postgres
# ^ no leading hyphen, colon between key and value