Dockerfile small case (systemctl)

Dockerfile small case (systemctl)

Dockerfile production (systemctl) image

  • Generate a new image based on sshd: new image
  • Create systemctl directory
mkdir systemctl
#创建systemctl的目录
  • Enter the systemctl directory
cd systemctl
#进入systemctl目录
  • Edit Dockerfile
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"]
#启动容器的时候执行的命令
  • Create mirror
docker build -t systemd:new .
#创建systemd:new的镜像
  • Start the container
docker run --privileged -it -v /sys/fs/cgroup:/sys/fs/cgroup:ro systemd:new /sbin/init
#启动容器
  • Into the container
docker ps -a
#查看容器的id
docker exec -it 容器的id bash
Published 140 original articles · 49 praises · 10,000+ views

Guess you like

Origin blog.csdn.net/double_happy111/article/details/105679301