gpt4 book ai didi

postgresql - Docker-Compose + postgres : database and user creation not working (works without compose)

转载 作者:行者123 更新时间:2023-11-29 13:42:04 25 4
gpt4 key购买 nike

docs for the postgres Docker image说明您可以使用环境变量使镜像在创建时创建用户和数据库。

我似乎无法使用 docker-compose 完成这项工作:

# docker-compose.yml
services:
postgresql:
image: postgres:alpine
environment:
POSTGRES_DB: iotplatform
POSTGRES_USER: iotplatform
POSTGRES_PASSWORD: iotplatform

这是我运行的:

docker-compose up -d --force-recreate postgresql
docker-compose exec postgresql psql -U iotplatform
# psql: FATAL: role "iotplatform" does not exist

当我运行 docker-compose exec postgresql env 时,我看到配置的环境变量。

日志没有说明任何特别的内容:

Attaching to iot-container-tracker_postgresql_1
postgresql_1 | 2018-12-17 17:35:05.754 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgresql_1 | 2018-12-17 17:35:05.754 UTC [1] LOG: listening on IPv6 address "::", port 5432
postgresql_1 | 2018-12-17 17:35:05.757 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgresql_1 | 2018-12-17 17:35:05.770 UTC [21] LOG: database system was shut down at 2018-12-17 17:35:03 UTC
postgresql_1 | 2018-12-17 17:35:05.772 UTC [1] LOG: database system is ready to accept connections
postgresql_1 | 2018-12-17 17:35:22.639 UTC [34] FATAL: role "iotplatform" does not exist

编辑:在没有 docker-compose 的情况下尝试过,它有效。

docker run --name some-postgres -e POSTGRES_PASSWORD=iotplatform -e POSTGRES_DB=iotplatform -e POSTGRES_USER=iotplatform -d postgres:alpine
docker exec -it some-postgres psql -U iotplatform
iotplatform=#

我错过了什么?

最佳答案

在运行 downup 后它工作了。显然 --force-recreate 不是一个足够硬的重置。

感谢@StéphaneJeandeaux 的帮助。

关于postgresql - Docker-Compose + postgres : database and user creation not working (works without compose),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53820456/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com