docker 构建如何使用 centos:systemd 运行 中间容器

docker build how to run intermediate containers with centos:systemd

我正在尝试构建一个基于 centos:systemd 的 docker 图像。在我的 Dockerfile 中,我正在 运行ning 一个依赖于 systemd 运行ning 的命令,该命令失败并出现以下错误:

Failed to get D-Bus connection: Operation not permitted
error: %pre(mod-php-7.1-apache2-zend-server-7.1.7-16.x86_64) scriptlet failed, exit status 1
Error in PREIN scriptlet in rpm package mod-php-7.1-apache2-zend-server-7.1.7-16.x86_64

如何使用 --privileged 和映射 -v /sys/fs/cgroup:/sys/fs/cgroup:ro 将中间容器获取到 运行?

如果我注释掉安装程序,只注释掉 运行 容器并手动执行安装程序,它就可以正常工作。

这是 Dockerfile

FROM centos/systemd
COPY ./ZendServer-9.1.0-RepositoryInstaller-linux.tar.gz /opt
RUN tar -xvf /opt/ZendServer-9.1.0-RepositoryInstaller-linux.tar.gz -C /opt/
RUN /opt/ZendServer-RepositoryInstaller-linux/install_zs.sh 7.1 java --automatic

如果您的安装程序需要 systemd 运行ning,我认为您将需要使用基础 centos/systemd 映像启动容器,手动 运行 命令,以及然后使用 docker commit 保存结果。在构建子映像时,基础映像 ENTRYPOINTCMD 不是 运行,但如果您启动容器并进行更改,它们会 运行。手动执行安装程序后,运行 docker commit {my_intermediate_container} {my_image}:{my_version},将花括号中的位替换为容器 name/hash、所需的映像名称和映像版本。

您还可以更改 Dockerfile 以在 运行安装程序之前启动 init。我不确定这是否适用于构建图像的上下文,但看起来像:

FROM centos/systemd
COPY ./ZendServer-9.1.0-RepositoryInstaller-linux.tar.gz /opt
RUN tar -xvf /opt/ZendServer-9.1.0-RepositoryInstaller-linux.tar.gz -C /opt/ \
    && /usr/sbin/init \
    && /opt/ZendServer-RepositoryInstaller-linux/install_zs.sh 7.1 java --automatic

docker 容器内的 LAMP 堆栈不需要 systemd - 我已经使用 docker-systemctl-replacement script 工作。它能够根据*.service 文件中的内容启动和停止服务。您可以尝试使用 ZendServer 通常在 docker 容器外执行的操作。