Postgresql 9.6在Centos 7的Docker容器中初始化失败

4
我正在尝试使用Centos7和PostgreSQL 9.6设置Docker镜像。
我使用centos:centos7镜像作为基础,并按照此页面的步骤进行操作:https://wiki.postgresql.org/wiki/YUM_Installation 初始化数据库的步骤。
sh-4.2# /usr/pgsql-9.6/bin/postgresql96-setup initdb
Failed to get D-Bus connection: Operation not permitted
failed to find PGDATA setting in postgresql-9.6.service

我尝试按照以下步骤启用systemd来运行CentOS镜像, https://hub.docker.com/_/centos/ 但没有起到作用。
我还尝试注释掉postgresql96-setup脚本中的语句。
#PGDATA=`systemctl show -p Environment "${SERVICE_NAME}.service" |
#                sed 's/^Environment=//' | tr ' ' '\n' |
#                sed -n 's/^PGDATA=//p' | tail -n 1`
#if [ x"$PGDATA" = x ]; then
#    echo "failed to find PGDATA setting in ${SERVICE_NAME}.service"
#    exit 1
#fi

现在 initdb 工作了。但启动服务时仍然显示相同的错误信息。
sh-4.2# systemctl enable postgresql-9.6.service
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-9.6.service to /usr/lib/systemd/system/postgresql-9.6.service.
sh-4.2#  systemctl start postgresql-9.6.service
Failed to get D-Bus connection: Operation not permitted

我错过了什么吗?有人可以帮我吗?


你不能使用官方的postgres镜像吗?https://hub.docker.com/_/postgres/ - Rao
@Rao 我也遇到了同样的问题。你提供的链接不是Centos7版本的。CentOS 7版本没有“latest”选项。他们提供的是9.5版本,而不是9.6版本,并且没有设置为root用户以进行进一步的安装:https://hub.docker.com/r/centos/postgresql-95-centos7/ - nealmcb
这似乎是解决“Failed to get D-Bus connection: Operation not permitted”问题的一种途径:https://serverfault.com/questions/824975/failed-to-get-d-bus-connection-operation-not-permitted - nealmcb
2个回答

1
“D-Bus连接:操作不允许”是Postgres想要与SystemD守护程序通信的提示。我正在使用https://github.com/gdraheim/docker-systemctl-replacement在centos-7的docker容器中运行Postgres,以避免这种情况。请注意,本文不需要解释,并保留HTML标签。

0

所述根本问题已得到解释并可通过以下答案解决:

Failed to get D-Bus connection: Operation not permitted - Server Fault

您可以自己创建新映像(centos7-systemd),但它并不像看起来那么困难。但务必要按照指示进行操作,通过以下方式运行新映像:

docker run --privileged -ti -e container=docker -v /sys/fs/cgroup:/sys/fs/cgroup centos7-systemd /usr/sbin/init

然后通过如下方法连接到它:

$ sudo docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6667f8acbe5c centos7-systemd "/usr/sbin/init" 33 minutes ago Up 13 minutes eager_brattain $ docker exec -it eager_brattain bash

然后在https://wiki.postgresql.org/wiki/YUM_Installation执行那些postgres说明,它们将正常工作。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接