以centos 7.2容器中運行httpd服務爲例子,默認下直接運行docker
[root@b0b2a3ed40d6 /]# systemctl start httpd.service Failed to get D-Bus connection: Operation not permitted
在網上找到的解決方法:
apache
建立Dockerfile建立一個基礎鏡像centos
FROM centos:7.2 MAINTAINER hpsfpcca@163.com ENV container docker RUN yum -y update && \ yum clean all && \ yum -y install systemd && \ yum clean all && \ (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"]
[root@dev-ops ~]# docker build -t centos_test_systemctl .
2.在上面鏡像的基礎上再構建apache鏡像
bash
FROM centos_test_systemctl MAINTAINER hpsfpcca@163.com RUN yum -y install httpd && \ yum clean all && \ systemctl enable httpd.service EXPOSE 80 CMD ["/usr/sbin/init"]
[root@dev-ops ~]# docker build -t centos_test_httpd .
3.而後就啓動容器socket
[root@dev-ops ~]# docker run --privileged -it -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p 80:80 centos_test_httpd