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.