【发布时间】:2026-01-23 16:55:03
【问题描述】:
我正在尝试从 docker-compose 文件中启动一个 postgres 容器并对其进行初始化。
docker-compose.yml
version: "3"
postgres:
image: "postgres"
command: bash -c "
postgres &&
createuser -l \"auser\"
"
我的目标是: 1)启动postgres容器 2) 创建用户
当前实现失败并出现以下错误
"root" execution of the PostgreSQL server is not permitted.
The server must be started under an unprivileged user ID to prevent
possible system security compromise. See the documentation for
more information on how to properly start the server.
【问题讨论】:
-
请参阅hub.docker.com/_/postgres 上的“如何扩展此图像”部分。该镜像支持通过环境变量创建用户,甚至可以运行任意脚本。这可能比试图用 CMD 搞砸要容易得多。
标签: postgresql docker docker-compose dockerfile