具体步骤这里再也不细说,直接看Dockerfile文件:html
FROM centos:7 MAINTAINER QUNXUE ENV VERSION=8.0.46 RUN yum install java-1.8.0-openjdk wget curl unzip iproute net-tools -y && \ yum clean all && \ rm -rf /var/cache/yum/* #RUN wget http://mirrors.shu.edu.cn/apache/tomcat/tomcat-8/v${VERSION}/bin/apache-tomcat-${VERSION}.tar.gz && \ COPY apache-tomcat-${VERSION}.tar.gz / RUN cd / && \ tar zxf apache-tomcat-${VERSION}.tar.gz && \ mv apache-tomcat-${VERSION} /usr/local/tomcat && \ rm -rf apache-tomcat-${VERSION}.tar.gz /usr/local/tomcat/webapps/* && \ mkdir -p /usr/local/tomcat/webapps/test && \ echo "ok" >/usr/local/tomcat/webapps/test/status.html && \ sed -i '1a JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom"' /usr/local/tomcat/bin/catalina.sh && \ ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ENV PATH $PATH:/usr/local/tomcat/bin WORKDIR /usr/local/tomcat EXPOSE 8080 CMD ["catalina.sh","run"]
docker build -t tomcat:v1 -f Dockerfile .
最后结果以下:java
查看镜像:python
docker run -d --name tomcat01 -p 8011:8080 tomcat:v1
经过宿主机的8011端口就能够访问到容器的tomcat服务。web
能够看到,咱们的容器跑起来了,可是,正常状况下,咱们的tomcat是跑war包的,后面学习CI/CD都须要用到Jenkins,他就有war包,因此咱们去官网下载一个Jenkins的war包吧。docker
再次制做镜像:apache
Dockerfile-jenkins文件:centos
FROM tomcat:v1 COPY jenkins.war /usr/local/tomcat/webapps/ROOT.war
制做Jenkins镜像:tomcat
docker build -t jenkins:v1 -f Dockerfile-jenkins .
测试镜像:app
docker run -d --name jenkins -p 8012:8080 jenkins:v1
查看结果:dom
咱们能够看到,Jenkins直接起来能够使用了!