I am trying to setup a docker image with Centos7 and PostgreSQL 9.6.
I use the centos:centos7 image as base, and I follow the steps from this page: https://wiki.postgresql.org/wiki/YUM_Installation
The step to initialize the 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
I tried to follow these steps to enable systemd for the CentOS image, https://hub.docker.com/_/centos/ But it does not help.
I also tried to comment out the stmts in the postgresql96-setup script
#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
Now the initdb works. But starting the service gives me the same error message
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
Did I miss anything? Anyone can help me out of this?
The "D-Bus connection: Operation not permitted" is a hint that Postgres wants to talk to the SystemD daemon. I am running Postgres in a centos-7 docker container by using the https://github.com/gdraheim/docker-systemctl-replacement to avoid that situation.
The underlying problem is explained and can be resolved with this answer:
Failed to get D-Bus connection: Operation not permitted - Server Fault
You make your own new image ( centos7-systemd
) but it isn't as hard as it looks. But be careful to do exactly what it says, running your new image via:
docker run --privileged -ti -e container=docker -v /sys/fs/cgroup:/sys/fs/cgroup centos7-systemd /usr/sbin/init
and then connect to it via eg
$ 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
Then run those postgres instructions at https://wiki.postgresql.org/wiki/YUM_Installation and they will work fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.