您好,登錄后才能下訂單哦!
小編給大家分享一下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]# ls atlassian-confluence-6.11.0.tar.gz c.txt jdk1.8.0_65.tar.gz
4、新建Dockerfile文件
[root@t-docker tomcat9]# cat Dockerfile FROM centos MAINTAINER chenzx #把宿主機當前上下文的c.txt拷貝到容器/opt路徑下 COPY c.txt /opt/container.txt #用ADD指令把java和tomcat壓縮包添加到容器中,并自動解壓 ADD atlassian-confluence-6.11.0.tar.gz /opt ADD jdk1.8.0_65.tar.gz /opt #安裝vim編輯器 RUN yum -y install vim #設置工作訪問時候的WORKDIR路徑,登錄落腳點 ENV MYPATH /opt WORKDIR $MYPATH #配置java與tomcat環境變量 ENV JAVA_HOME /opt/jdk1.8.0_65 ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar ENV CATALINA_HOME /opt/atlassian-confluence-6.11.0 ENV CATALINA_BASE /opt/atlassian-confluence-6.11.0 ENV 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 719MB Step 1/15 : FROM centos ---> 5182e96772bf Step 2/15 : MAINTAINER chenzx ---> Running in d04f35bb304d Removing intermediate container d04f35bb304d ---> b1535d029856 Step 3/15 : COPY c.txt /opt/container.txt ---> ef3569b7b95d Step 4/15 : ADD atlassian-confluence-6.11.0.tar.gz /opt ---> 0aed885f1740 Step 5/15 : ADD jdk1.8.0_65.tar.gz /opt ---> 56ef4a5d806c Step 6/15 : RUN yum -y install vim ---> Running in 96d23e66cbc6 Loaded plugins: fastestmirror, ovl Determining fastest mirrors * base: mirrors.aliyun.com * extras: mirrors.aliyun.com Step 7/15 : ENV MYPATH /opt ---> Running in f8b147007a67 Removing intermediate container f8b147007a67 ---> 88cd40f1df40 Step 8/15 : WORKDIR $MYPATH ---> Running in 55ba5490990a Removing intermediate container 55ba5490990a ---> 2bdeb9172d40 Step 9/15 : ENV JAVA_HOME /opt/jdk1.8.0_65 ---> Running in e5edb170b825 Removing intermediate container e5edb170b825 ---> 2b315b03c617 Step 10/15 : ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar ---> Running in a3c6d7e8a539 Removing intermediate container a3c6d7e8a539 ---> 5a49c2cefc2a Step 11/15 : ENV CATALINA_HOME /opt/atlassian-confluence-6.11.0 ---> Running in 6c105a803c9c Removing intermediate container 6c105a803c9c ---> 8a4879a4d399 Step 12/15 : ENV CATALINA_BASE /opt/atlassian-confluence-6.11.0 ---> Running in 894570c08307 Removing intermediate container 894570c08307 ---> 843b28783e33 Step 13/15 : ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin ---> Running in 14ea7d7ae882 Removing intermediate container 14ea7d7ae882 ---> 2fbdf4cb96b6 Step 14/15 : EXPOSE 8080 ---> Running in 0b55f91baea1 Removing intermediate container 0b55f91baea1 ---> 340b421dfc43 Step 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 551c8481362e Removing intermediate container 551c8481362e ---> 4edb0a9de409 Successfully built 4edb0a9de409 Successfully tagged tomcat9:latest [root@t-docker tomcat9]#
[root@t-docker tomcat9]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE tomcat9 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 ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a4174d4abeba 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 -l total 0 drwxr-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.txt drwxr-xr-x 9 root root 268 Feb 24 2016 jdk1.8.0_65 drwxr-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鏡像”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。