操作系统:centos7.2.1511
centos镜像:centos7.2.1511
安装docker
yum -y install docker
启动docker
systemctl start docker
发现启动不了,报错:
Error starting daemon: SELinux is not supported with the overlay2 graph driver on this kernel. Either boot into a newer kernel or disable selinux ...enabled=false)
修改配置文件
vim /etc/sysconfig/docker
OPTIONS='--selinux-enabled=false'
再次启动服务
systemctl start docker
systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2018-07-17 05:48:54 CST; 20s ago
Docs: http://docs.docker.com
下载centos7.2镜像
docker pull daocloud.io/library/centos:centos7.2.1511
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
daocloud.io/library/centos centos7.2.1511 0a2bad7da9b5 8 months ago 195 MB
Systemd整合
因为 systemd 要求 CAPSYSADMIN 权限,从而得到了读取主机 cgroup 的能力,CentOS7 中已经用 fakesystemd 代替了 systemd 来解决依赖问题,如果仍然希望使用 systemd,可用下面的 Dockerfile
cat > Dockerfile <<EOF
FROM 0a2bad7da9b5
MAINTAINER Testder 10000@testder.cn
ENV container docker
RUN yum -y swap -- remove fakesystemd -- install systemd systemd-libs
RUN yum -y update; 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"]
EOF
构建基础镜像
docker build --rm -t centos7.2 .
后台运行Centos容器
为了运行一个包含 systemd 的容器,您需要使用--privileged选项, 并且挂载主机的 cgroups 文件夹。 下面是运行包含 systemd 容器的示例命令:
docker run -itd --name centos7.2 --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro centos7.2
641f23dce23355729dfb8e99e5df467574eb116afbb1c50e71e272e952451d03
使用exec进入Centos容器,systemd启动成功
docker exec -it centos7.2 /bin/bash
[root@641f23dce233 /]# yum -y install httpd
[root@641f23dce233 /]# systemctl start httpd
网友评论