文章索引
1、创建Dockerfile
[root@linux-node1 ~]# mkdir /opt/dockerfile/Tomcat [root@linux-node1 ~]# cd /opt/dockerfile/Tomcat/ [root@linux-node1 Tomcat]# touch Dockerfile
2、下载apache-tomcat 及jdk
[root@linux-node1 Tomcat]# wget http://download.zhsir.org/Java/jdk-8u60-linux-x64.tar.gz [root@linux-node1 Tomcat]# wget http://download.zhsir.org/Java/apache-tomcat-8.0.27.tar.gz
3、编写Dockerfile
#This is tomcat Dockerfile FROM centos MAINTAINER zhangyang zhangyang1@afocus.com.cn ADD ./apache-tomcat-8.0.27.tar.gz /root ADD ./jdk-8u60-linux-x64.tar.gz /root #set environment variable ENV JAVA_HOME /root/jdk1.8.0_60 ENV PATH $JAVA_HOME/bin:$PATH #define entry point which will be run first when the container starts up ENTRYPOINT /root/apache-tomcat-8.0.27/bin/startup.sh && tail -F /root/apache-tomcat-8.0.27/logs/catalina.out
4、创建镜像
[root@linux-node1 Tomcat]# docker build -t youngcheng/tomcat:v1 . Sending build context to Docker daemon 190.4 MB Step 1 : FROM centos ---> 36540f359ca3 Step 2 : MAINTAINER zhangyang zhangyang1@afocus.com.cn ---> Running in d4a7eb6e6d5e ---> 033cecc4f165 Removing intermediate container d4a7eb6e6d5e Step 3 : ADD ./apache-tomcat-8.0.27.tar.gz /root ---> c2c9585b5e96 Removing intermediate container 4e4f8b15eb4e Step 4 : ADD ./jdk-8u60-linux-x64.tar.gz /root ---> fb869ba9158c Removing intermediate container 4c708b8aae8f Step 5 : ENV JAVA_HOME /root/jdk1.8.0_60 ---> Running in e6129ce91d9e ---> 9aa61e153975 Removing intermediate container e6129ce91d9e Step 6 : ENV PATH $JAVA_HOME/bin:$PATH ---> Running in 7c131b684dad ---> e450b14b61b0 Removing intermediate container 7c131b684dad Step 7 : ENTRYPOINT /root/apache-tomcat-8.0.27/bin/startup.sh && tail -F /root/apache-tomcat-8.0.27/logs/catalina.out ---> Running in 73b065c76e73 ---> 695706e58f6e Removing intermediate container 73b065c76e73 Successfully built 695706e58f6e
5、启动容器
[root@linux-node1 Tomcat]# docker run -d -p 8090:8080 695706e58f6e c1e7741b1a89b004f0aeb91eb5b72212699595c519855608b81f25a7ce77a34b
访问:http://192.168.56.10:8090
注意:实际环境中可以用-v参数来挂载Tomcat日志文件、程序所在目录已经Tomcat相关的配置。
!评论内容需包含中文