繁体   English   中英

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

[英]Postgresql 9.6 initdb fails in Centos 7 docker container

我正在尝试使用Centos7和PostgreSQL 9.6设置docker镜像。

我使用centos:centos7图像作为基础,我按照此页面中的步骤操作: https ://wiki.postgresql.org/wiki/YUM_Installation

初始化DB的步骤

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

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

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

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

无法获得D-Bus连接:不允许操作 - 服务器故障

你制作了自己的新图像( 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说明,它们将正常工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM