Dockerfile小案例(systemctl)
Dockerfile制作(systemctl)镜像
- 基于sshd:new镜像生成新的镜像
- 创建systemctl目录
mkdir systemctl
#创建systemctl的目录
cd systemctl
#进入systemctl目录
vim Dockerfile
#编辑Dockerfile
FROM sshd:new
#指定sshd:new的镜像
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" ]
#挂载宿主机的/sys/fs/cgroup
CMD ["/usr/sbin/init"]
#启动容器的时候执行的命令
docker build -t systemd:new .
#创建systemd:new的镜像
docker run --privileged -it -v /sys/fs/cgroup:/sys/fs/cgroup:ro systemd:new /sbin/init
#启动容器
docker ps -a
#查看容器的id
docker exec -it 容器的id bash