小编给大家分享一下docker中Dockerfile如何自定义tomcat镜像,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
1、创建目录
[root@t-docker chenzx]# mkdir tomcat9
2、在上述目录下touch c.txt,为了演示copy指令的功能
[root@t-docker tomcat9]# touch c.txt
3、将jdk和tomcat安装的压缩包拷贝进上一步目录
[root@t-docker tomcat9]# lsatlassian-confluence-6.11.0.tar.gz c.txt jdk1.8.0_65.tar.gz
4、新建Dockerfile文件
[root@t-docker tomcat9]# cat Dockerfile FROM centosMAINTAINER chenzx#把宿主机当前上下文的c.txt拷贝到容器/opt路径下COPY c.txt /opt/container.txt#用ADD指令把java和tomcat压缩包添加到容器中,并自动解压ADD atlassian-confluence-6.11.0.tar.gz /optADD jdk1.8.0_65.tar.gz /opt#安装vim编辑器RUN yum -y install vim#设置工作访问时候的WORKDIR路径,登录落脚点ENV MYPATH /optWORKDIR $MYPATH#配置java与tomcat环境变量ENV JAVA_HOME /opt/jdk1.8.0_65ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarENV CATALINA_HOME /opt/atlassian-confluence-6.11.0ENV CATALINA_BASE /opt/atlassian-confluence-6.11.0ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin#容器运行时监听的端口EXPOSE 8080#启动时运行tomcat#ENTRYPOINT ["/opt/atlassian-confluence-6.11.0/bin/startup.sh"]#CMD ["/opt/atlassian-confluence-6.11.0/bin/catalina.sh","run"]CMD /opt/atlassian-confluence-6.11.0/bin/startup.sh && tail -F /opt/atlassian-confluence-6.11.0/logs/catalina.out
5、构建
[root@t-docker tomcat9]# docker build -t tomcat9 .Sending build context to Docker daemon 719MBStep 1/15 : FROM centos ---> 5182e96772bfStep 2/15 : MAINTAINER chenzx ---> Running in d04f35bb304dRemoving intermediate container d04f35bb304d ---> b1535d029856Step 3/15 : COPY c.txt /opt/container.txt ---> ef3569b7b95dStep 4/15 : ADD atlassian-confluence-6.11.0.tar.gz /opt ---> 0aed885f1740Step 5/15 : ADD jdk1.8.0_65.tar.gz /opt ---> 56ef4a5d806cStep 6/15 : RUN yum -y install vim ---> Running in 96d23e66cbc6Loaded plugins: fastestmirror, ovlDetermining fastest mirrors * base: mirrors.aliyun.com * extras: mirrors.aliyun.comStep 7/15 : ENV MYPATH /opt ---> Running in f8b147007a67Removing intermediate container f8b147007a67 ---> 88cd40f1df40Step 8/15 : WORKDIR $MYPATH ---> Running in 55ba5490990aRemoving intermediate container 55ba5490990a ---> 2bdeb9172d40Step 9/15 : ENV JAVA_HOME /opt/jdk1.8.0_65 ---> Running in e5edb170b825Removing intermediate container e5edb170b825 ---> 2b315b03c617Step 10/15 : ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar ---> Running in a3c6d7e8a539Removing intermediate container a3c6d7e8a539 ---> 5a49c2cefc2aStep 11/15 : ENV CATALINA_HOME /opt/atlassian-confluence-6.11.0 ---> Running in 6c105a803c9cRemoving intermediate container 6c105a803c9c ---> 8a4879a4d399Step 12/15 : ENV CATALINA_BASE /opt/atlassian-confluence-6.11.0 ---> Running in 894570c08307Removing intermediate container 894570c08307 ---> 843b28783e33Step 13/15 : ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin ---> Running in 14ea7d7ae882Removing intermediate container 14ea7d7ae882 ---> 2fbdf4cb96b6Step 14/15 : EXPOSE 8080 ---> Running in 0b55f91baea1Removing intermediate container 0b55f91baea1 ---> 340b421dfc43Step 15/15 : CMD /opt/atlassian-confluence-6.11.0/bin/startup.sh && tail -F /opt/atlassian-confluence-6.11.0/logs/catalina.out ---> Running in 551c8481362eRemoving intermediate container 551c8481362e ---> 4edb0a9de409Successfully built 4edb0a9de409Successfully tagged tomcat9:latest[root@t-docker tomcat9]#
[root@t-docker tomcat9]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEtomcat9 latest 4edb0a9de409 3 minutes ago 1.3GB
6、run
[root@t-docker tomcat9]#docker run -d -p 9080:8090 --name myt9 \-v /volume/test:/opt/atlassian-confluence-6.11.0/test \-v /volume/tomcatlogs:/opt/atlassian-confluence-6.11.0/logs \--privileged=true \tomcat9
-v就是数据卷的意思,volume
[root@t-docker tomcat9]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESa4174d4abeba tomcat9 "/bin/sh -c '/opt/at…" 7 seconds ago Up 6 seconds 8080/tcp, 0.0.0.0:9080->8090/tcp myt9
7、验证
[root@t-docker tomcat9]# docker exec a4174d4abeba ls -ltotal 0drwxr-xr-x 1 1000 1000 42 Sep 2 03:41 atlassian-confluence-6.11.0-rw-r--r-- 1 root root 0 Sep 2 02:38 container.txtdrwxr-xr-x 9 root root 268 Feb 24 2016 jdk1.8.0_65drwxr-x--- 2 root root 102 Sep 2 03:41 logs
8、综合前述的容器卷测试web服务的发布
以后发版,就在宿主机上的/volume/test里面发版即可,具体测试略。
[root@t-docker tomcat9]# cd /volume/test
[root@t-docker test]# mkdir WEB-INF
[root@t-docker test]# cd WEB-INF/
以上是“docker中Dockerfile如何自定义tomcat镜像”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注编程网行业资讯频道!