Postgres12ではデータベースの初期設定時にPOSTGRES_PASSWORD環境変数が必要
Closed this issue · 1 comments
READMEにある手順
export DB_USER=enju_leaf DB_NAME=enju_leaf_production DB_PASS=admin # .env.production に合わせる
docker-compose up -d db \
&& sleep 10 \
&& docker-compose exec -u postgres db sh -c "echo create user ${DB_USER} with password \'${DB_PASS}\' createdb\; | psql -f -" \
&& docker-compose exec -u postgres db createdb -U ${DB_USER} ${DB_NAME}
を実行すると
Error response from daemon: Container *** is restarting, wait until the container is running
となり失敗する。
docker-compose logsによると
db_1 | Error: Database is uninitialized and superuser password is not specified.
db_1 | You must specify POSTGRES_PASSWORD to a non-empty value for the
db_1 | superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".
db_1 |
db_1 | You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
db_1 | connections without a password. This is not recommended.
db_1 |
db_1 | See PostgreSQL documentation about "trust":
db_1 | https://www.postgresql.org/docs/current/auth-trust.html
となっているため、一時的にdocker-compose.ymlで
environment:
- POSTGRES_PASSWORD=admin
する等の対応が必要になる。
docker-compose.yml に
environment:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
を入れたのでホスト環境で POSTGRES_PASSWORD
環境変数を宣言したりしなかったりすることでコンテナ内に POSTGRES_PASSWORD
を設定したりしなかったりするように変更しました。