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

我正在尝试构build一个基于centos:systemd的docker映像。 在我的Dockerfile中,我正在运行一个依赖于systemd运行的命令,失败的原因如下:

 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运行,我想您将需要启动一个容器与基本centos/systemd映像,手动运行命令,然后使用docker commit保存结果。 基本图像ENTRYPOINTCMD不会在构build子图像时运行,但是如果启动容器并进行更改,则它们会运行。 在手动执行安装程序之后,运行docker commit {my_intermediate_container} {my_image}:{my_version} ,用容器名称/散列,所需的映像名称和映像版本replace花括号中的位。

在运行安装程序之前,您也可以更改Dockerfile来启动init。 我不确定这是否能在build立图像的环境下工作,但看起来像:

 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脚本 。 它可以根据* .service文件中的内容来启动和停止服务。 你可以试试ZendServer通常在Docker容器之外做什么。