本文講解如何製作自己的tomcat映象,並使用tomcat部署專案
tomcat、jdk安裝包,dockerfile檔案
jdk-8u301-linux-x64.tar.gz -> jdk1.8.0_301
apache-tomcat-7.0.107.tar.gz -> apache-tomcat-7.0.107
官方指定命名
Dockerfile
,這樣構建的時候不用加-f
引數指定檔案
FROM centos
MAINTAINER xiao<[email protected]>
COPY readme.txt /usr/local/readme.txt
ADD jdk-8u301-linux-x64.tar.gz /usr/local
ADD apache-tomcat-7.0.107.tar.gz /usr/local
RUN yum -y install vim
ENV MYPATH /usr/local
WORKDIR $MYPATH
ENV JAVA_HOME /usr/local/jdk1.8.0_301
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-7.0.107
ENV CATALINE_BASH /usr/local/apache-tomcat-7.0.107
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINE_HOME/bin
EXPOSE 8080
CMD /usr/local/apache-tomcat-7.0.107/bin/startup.sh && tail -f /usr/local/apache-tomcat-7.0.107/bin/logs/catalina.out
docker build -t diytomcat . # 自動尋找Dockerfile檔案
構建成功:
Successfully built e68ad8caa2a4
Successfully tagged diytomcat:latest
/webapps/test
部署的專案路徑,瀏覽器存取ip:port/test
docker run -it -p 9090:8080 --name xiaoTomcat -v /home/xiao/build/tomcat/test:/usr/local/apache-tomcat-7.0.107/webapps/test -v /home/xiao/build/tomcat/tomcatlogs/:/usr/local/apache-tomcat-7.0.107/logs diytomcat
資料卷掛載成功
已經掛載了資料卷,所以編寫宿主機的專案檔案就可以了
在掛載路徑 /home/xiao/build/tomcat/test
下
web.xml
,內容如下:<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
</web-app>
index.jsp
,內容如下:<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<body>
<h2>Hello World!</h2>
<h2>xiao</h2>
<%
System.out.println("my tomcat project logs");
%>
</body>
</html>
url:ip:port/test
tail -f catalina.out