Skip to content

Report errors "FATAL: role "XXX" does not exist" when POSTGRES_USER is customized. #1138

@Chr15t0pher

Description

@Chr15t0pher

I'm a totally newbie, trying to using a shell script to run postgres image.
Here is my code:

DB_USER="${POSTGRES_USER:=admin}"
DB_PASSWORD="${POSTGRES_PASSWORD:=admin}"
DB_NAME="${POSTGRES_DB:=scaffold}"
DB_PORT="${POSTGRES_PORT:=5432}"
DB_HOST="${POSTGRES_HOST:=localhost}"

docker run \
  --name "postgres_$(date '+%s')" \
  -e POSTGRES_USER=${DB_USER} \
  -e POSTGRES_PASSWORD=${DB_PASSWORD} \
  -e POSTGRES_DB=${DB_NAME} \
  -p "${DB_PORT}":5432 \
  -d \
  postgres -N 1000

until PGPASSWORD="${DB_PASSWORD}" psql -h "${DB_HOST}" -U "${DB_USER}" -p "${DB_PORT}" -d "postgres" -c '\q'; do
  >&2 echo "Postgres is still unavailable - sleeping"
  sleep 1
done

The errors I've been able to see are:

psql: error: connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL:  role "admin" does not exist

What am I missing and how can I fix this so I can actually proceed with Postgres?
When i set DB_USER to the default value postgres, it is Ok. But i just don't know the reason.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions