4.3 构建Systemctl镜像
mkdir /opt/systemctl cd /opt/systemctl
vim Dockerfile FROM sshd:centos MAINTAINER this is systemctl image <xc> ENV container docker #除了systemd-tmpfiles-setup.service,删除其它所有文件 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"]
//生成镜像 docker build -t systemd:centos .
//启动容器,并挂载宿主机目录挂载到容器中,和进行初始化 docker run --privileged -d -P -v /sys/fs/cgroup:/sys/fs/cgroup:ro systemd:centos /sbin/init #--privileged:使container内的root拥有真正的root权限。否则,container内的root只是外部的一个普通用户权限。 docker ps -a
//进入容器 docker exec -it 9e4f4b082994 bash yum -y install httpd systemctl start httpd systemctl status httpd
方法二:
方法二: docker run --privileged -it -P -v /sys/fs/cgroup:/sys/fs/cgroup:ro systemd:centos /sbin/init &
4.4 构建tomcat 镜像
mkdir /opt/tomcat cd /opt/tomcat
vim Dockerfile FROM centos:7 MAINTAINER this is tomcat image <xc> ADD jdk-8u91-linux-x64.tar.gz /usr/local/ WORKDIR /usr/local/ RUN mv jdk1.8.0_91 /usr/local/java ENV JAVA_HOME /usr/local/java ENV JRE_HOME ${JAVA_HOME}/jre ENV CLASSPATH .:${JAVA_HOME}/lib:${JRE_HOME}/lib ENV PATH $JAVA_HOME/bin:$PATH ADD apache-tomcat-8.5.16.tar.gz /usr/local/ WORKDIR /usr/local/ RUN mv apache-tomcat-8.5.16 /usr/local/tomcat EXPOSE 8080 #CMD ["/usr/local/tomcat/bin/catalina.sh","run"] ENTRYPOINT ["/usr/local/tomcat/bin/catalina.sh","run"]
//创建新镜像 docker build -t tomcat:centos .
docker run -d --name tomcat01 -p 1216:8080 tomcat:centos http://192.168.147.105:1216