[英]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以避免這種情況。
解釋了潛在的問題,可以通過以下答案解決:
你制作了自己的新圖像( 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.