【问题标题】:Initialise postgres on centos docker image fails with Failed to get D-Bus connection: Operation not permitted在 centos docker 映像上初始化 postgres 失败并出现 Failed to get D-Bus connection: Operation not allowed
【发布时间】:2018-03-11 16:53:35
【问题描述】:

我正在尝试在 docker 镜像上安装 postgres,基础镜像正在运行 centos。

我按照How to Install PostgreSQL Relational Databases on CentOS 7 的说明进行操作,这是我的 Dockerfile:

FROM our-internal-docker-registry.org/centos:7.3.1611
RUN yum install -y postgresql-server postgresql-contrib
RUN postgresql-setup initdb

第一个 RUN 命令成功,但第二个失败:

Step 3/3 : RUN postgresql-setup initdb
 ---> Running in d26f43467aa0
Failed to get D-Bus connection: Operation not permitted
failed to find PGDATA setting in postgresql.service
The command '/bin/sh -c postgresql-setup initdb' returned a non-zero code: 1

我承认我对接下来要做什么一无所知,因为我对 postgres 或者实际上是 linux 不是很熟悉。希望给点建议。

【问题讨论】:

  • 错误提示 initdb 正在尝试启动 postgres 服务,因此它可以初始化 DB。但是在 docker 内部没有 systemd 或 init,所以这是行不通的。您应该查看官方 postgres 映像的原始 Dockerfile 并从那里了解需要做什么
  • 好建议。搜索将我带到这里:github.com/sclorg/postgresql-container/blob/master/9.5/…。谢谢@TarunLalwani
  • 官方 postgres 镜像 (github.com/docker-library/postgres) 基于 debian 而我的组织选择的发行版是 centos,所以我还是有点天真/迷失。
  • 别担心,看看他们使用的entrypoint.sh 文件,它会先在后台进程中启动服务器,初始化数据库,然后重新启动进程
  • 是否有组织要求所有容器和 Dockerfile 都基于 CentOS?理想情况下,基本操作系统发行版应该是无关紧要的——即没有人在容器内运行命令——你可以只使用官方的library/postgres:9.6library/postgres:9.6-alpine 图像。否则,您将无法翻译 Debian 或 Alpine docker-entrypoint.sh 脚本以在您的基础 centos 映像中工作。

标签: postgresql docker centos


【解决方案1】:

“D-Bus 连接:不允许操作”是它想要联系 SystemD 守护程序的提示。我在 centos 上使用 postgres 和 https://github.com/gdraheim/docker-systemctl-replacement 来避免这种情况。

【讨论】:

    猜你喜欢
    • 2019-07-24
    • 2015-04-24
    • 2015-09-01
    • 1970-01-01
    • 2022-08-03
    • 2020-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多