Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Centos 7 docker容器中的Postgresql 9.6 initdb失败_Postgresql_Docker_Centos7 - Fatal编程技术网

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

Centos 7 docker容器中的Postgresql 9.6 initdb失败,postgresql,docker,centos7,Postgresql,Docker,Centos7,我正在尝试使用Centos7和PostgreSQL 9.6设置docker映像 我使用centos:centos7图像作为基础,并遵循本页中的步骤: 初始化数据库的步骤 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

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

我使用centos:centos7图像作为基础,并遵循本页中的步骤:

初始化数据库的步骤

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, 但这没有帮助

我还试图注释掉postgresql96安装脚本中的STMT

#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

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

基本问题已被解释,并可通过以下答案解决:

您可以制作自己的新图像(
centos7 systemd
),但它并不像看上去那么难。但是,请务必严格按照上面所说的去做,通过以下方式运行您的新图像:

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

然后通过例如


$sudo docker ps
容器ID映像命令已创建状态端口名称
6667f8acbe5c centos7 systemd“/usr/sbin/init”33分钟前上升13分钟
$docker exec-it渴望之旅


然后在运行这些postgres指令,它们将正常工作。

D-Bus connection:Operation not allowed(D-Bus连接:不允许操作)是一个提示,表示postgres希望与SystemD守护进程对话。我使用centos-7 docker容器运行Postgres,以避免出现这种情况。

您不能使用官方Postgres image@Rao吗?我也有同样的问题。您链接到的不是Centos7。CentOS 7版本没有“最新版本”。他们链接到的是9.5,而不是9.6,并且没有设置为根目录以供以后安装:这似乎是一个解决方案的路径,因为
无法获得D总线连接:不允许操作