docker-compose: FATAL: password authentication failed for user "postgres"

675 views Asked by At

My docker container for postgres:11 in my docker-compose setup is acting up.

Whenever I attempt to pass POSTGRES_USER / POSTGRES_PASSWORD to override the default combination of postgres:password, I get the following error:

postgres    | 2020-10-22 01:33:33.759 UTC [72] FATAL:  password authentication failed for user "postgres"
postgres    | 2020-10-22 01:33:33.759 UTC [72] DETAIL:  Role "postgres" does not exist.

Here is the docker-compose setup:

version: '3.4'

services:
  postgres:
    image: postgres:11
    container_name: postgres
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_DB=orca
      - POSTGRES_USER=${POSTGRES_USER:-postgres}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-password}
      - POSTGRES_SCHEMA=clinics

Command:

POSTGRES_USER=arthur POSTGRES_PASSWORD=password docker-compose -f docker-compose.development.yml up

Overriding only for the docker container itself outside of docker-compose does not result in the same problem however. The following command does not result in the same errors.

$ docker container run -e POSTGRES_USER=arthur -e POSTGRES_PASSWORD=password -e POSTGRES_DB=orca -e POSTGRES_SCHEMA=clinics postgres:11

I've removed volumes, env_file properties to reduce the sources of issue, and yet I still can't find the source of the issue. Anybody has any idea of why this could be happening or steps I could use to investigate further?

1

There are 1 answers

1
Ali Asgari On

Docker compose does not support bash or other shells features. The way you're trying to set default for the environment variable:

- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-password}

simply does not work.

Try using simple substitution of environment variables as explained here.

You can do defaulting stuff out of docker compose file while executing the command.