Postgresql 9.6 initdb在Centos 7 docker容器中失败

时间:2016-11-14 20:37:43

标签: postgresql docker centos7

我正在尝试使用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

我尝试按照以下步骤为CentOS映像启用systemd, https://hub.docker.com/_/centos/ 但它没有帮助。

我还尝试在postgresql96-setup脚本中注释掉stmts

#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

我错过了什么吗?有人可以帮我解决这个问题吗?

2 个答案:

答案 0 :(得分:1)

" D-Bus连接:不允许操作"暗示Postgres想要与SystemD守护进程通信。我使用https://github.com/gdraheim/docker-systemctl-replacement在centos-7 docker容器中运行Postgres以避免这种情况。

答案 1 :(得分:0)

解释了潜在的问题,可以通过以下答案解决:

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

你制作了自己的新形象(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

然后通过例如

连接到它

{{1}}

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