Dockerfile

FROM centos:7
ENV container docker
VOLUME ["/sys/fs/cgroup"]
RUN yum -y update
RUN yum install -y httpd
RUN systemctl start httpd.service
ADD . /code
WORKDIR /code

docker-compose.yml
version: '2'
services:
web:
   privileged: true
   build: .
   ports:
    - "80:80"
   volumes:
    - .:/code

命令
docker-compose build

错误:

步骤6:运行systemctl启动httpd.service
--->在5989c6576ac9中运行
?[91m未能获得D-Bus连接:不允许操作
[[0m] [31mERROR?[0m:服务'web'生成失败:命令'/bin/sh -c syste
mctl start httpd.service'返回了非零代码:1

Obs :在Windows 7上运行:(

有小费吗?

最佳答案

centos docker image repository中所述,Systemd在默认情况下不处于 Activity 状态。为了使用systemd,您将需要包含类似于以下示例Dockerfile的文本:

FROM centos:7
MAINTAINER "you" <[email protected]>
ENV container docker
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
VOLUME [ "/sys/fs/cgroup" ]
CMD ["/usr/sbin/init"]

该Dockerfile删除了许多可能导致问题的单位文件。从这里,您就可以构建基础镜像了。
$ docker build --rm -t local/c7-systemd .

为了使用上面创建的启用了systemd的基本容器,您需要将Dockerfile更改为:
FROM local/c7-systemd
ENV container docker
VOLUME ["/sys/fs/cgroup"]
RUN yum -y update
RUN yum install -y httpd
RUN systemctl start httpd.service
ADD . /code
WORKDIR /code

关于docker - docker + systemctl不允许操作systemctl,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37500158/

10-09 06:50