原料:
步骤
1、准备压缩包
jdk-8u301-linux-x64.tar.gz
jdk1.8.0_301
apache-tomcat-7.0.107.tar.gz
apache-tomcat-7.0.107
2、编写dockerfile文件
官方指定命名Dockerfile,这样构建的时候不用加-f指定文件
FROM centos
MAINTAINER xiao<find_onepiece@163.com>
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
3、执行构建
docker build -t diytomcat . #自动寻找Dockerfile文件
构建成功
Successfully built e68ad8caa2a4
Successfully tagged diytomcat:latest
4、启动容器
/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
5、访问查看
6、发布项目
已经挂载了卷,所以编写宿主机的项目文件就可以了
在挂载路径 /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>