本文讲解如何制作自己的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
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
,内容如下:
index.jsp
,内容如下:<%@ page contentType="text/html;charset=UTF-8" language="java" %>
Hello World!
xiao
<%
System.out.println("my tomcat project logs");
%>
url:ip:port/test
tail -f catalina.out