1、编写Dockerfile文件
vi Dockerfile
FROM centos:latest
MAINTAINER john
# now add java and tomcat support in the container
ADD jdk-8u162-linux-x64.tar.gz /usr/local/
ADD apache-tomcat-8.5.63.tar.gz /usr/local/
# configuration of java and tomcat ENV
ENV JAVA_HOME /usr/local/jdk1.8.0_162
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-8.5.63
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
# container listener port
EXPOSE 8080
# startup web application services by self
CMD /usr/local/apache-tomcat-8.5.63/bin/catalina.sh run
2、构建镜像
[root@muze1 local]$ docker build -t zxk/tomcat -f Dockerfile .
Sending build context to Docker daemon 4.203GB
Step 1/10 : FROM f1cb7c7d58b7
---> f1cb7c7d58b7
Step 2/10 : MAINTAINER john
---> Using cache
---> 8a96f3f36d43
Step 3/10 : ADD jdk-8u162-linux-x64.tar.gz /usr/local/
---> e794e074803a
Step 4/10 : ADD apache-tomcat-8.5.63.tar.gz /usr/local/
---> 3bce28a37a69
Step 5/10 : ENV JAVA_HOME /usr/local/jdk1.8.0_162
---> Running in 1a86f4f2968f
Removing intermediate container 1a86f4f2968f
---> ac439ffdad50
Step 6/10 : ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
---> Running in fcf4c546a3a8
Removing intermediate container fcf4c546a3a8
---> d06e49e5d89f
Step 7/10 : ENV CATALINA_HOME /usr/local/apache-tomcat-8.5.63
---> Running in 52a592af2987
Removing intermediate container 52a592af2987
---> 84cea69ee141
Step 8/10 : ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
---> Running in e9fde32f5199
Removing intermediate container e9fde32f5199
---> 0553f42df35e
Step 9/10 : EXPOSE 8080
---> Running in 8a91d52efeba
Removing intermediate container 8a91d52efeba
---> 5f10c22147ff
Step 10/10 : CMD /usr/local/apache-tomcat-8.5.63/bin/catalina.sh run
---> Running in 2ec901a9ebc7
Removing intermediate container 2ec901a9ebc7
---> 0f5c331625b4
Successfully built 0f5c331625b4
Successfully tagged zxk/tomcat:latest
3、通过创建好的镜像启动一个容器:
4、访问测试
5、将宿主机webapps目录挂载至容器的webapps
[root@muze1 webapps]$ docker run -d -p 8080:8080 -v /usr/local/webapps:/usr/local/apache-tomcat-8.5.63/webapps --name zxk1_tomcat zxk/tomcat:latest
cccd417e2833172ebd90a35669328f90d5b067fcb544e91c9d25d2107ea37bd7
最后将TestWas.war放到宿主机建好的webapps目录下面,
测试业务是否能访问:
标签:10,tomcat,local,---,usr,HOME,Dockerfile,war From: https://www.cnblogs.com/vzhangxk/p/16910577.html