DockerFile 自定义镜像Tomcat9

一、新建目录

DockerFile 自定义镜像Tomcat9

二、 在上述目录下touch c.txt

DockerFile 自定义镜像Tomcat9

三、将jdk和tomcat安装的压缩包拷贝进上一步目录

DockerFile 自定义镜像Tomcat9

四、编写DockerFile

DockerFile 自定义镜像Tomcat9

FROM         centos
MAINTAINER    czy<>
#把宿主机当前上下文的c.txt拷贝到容器/usr/local/路径下
COPY c.txt /usr/local/cincontainer.txt
#把java与tomcat添加到容器中
ADD jdk-8u171-linux-x64.tar.gz /usr/local/
ADD apache-tomcat-9.0.30.tar.gz /usr/local/
#安装vim编辑器
RUN yum -y install vim
#设置工作访问时候的WORKDIR路径,登录落脚点
ENV MYPATH /usr/local
WORKDIR $MYPATH
#配置java与tomcat环境变量
ENV JAVA_HOME /usr/local/jdk1.8.0_171
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.30
ENV CATALINA_BASE /usr/local/apache-tomcat-9.0.30
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
#容器运行时监听的端口
EXPOSE  8080
#启动时运行tomcat
# ENTRYPOINT ["/usr/local/apache-tomcat-9.0.30/bin/startup.sh" ]
# CMD ["/usr/local/apache-tomcat-9.0.30/bin/catalina.sh","run"]
CMD /usr/local/apache-tomcat-9.0.30/bin/startup.sh && tail -F /usr/local/apache-tomcat-9.0.30/bin/logs/catalina.out

五、构建

DockerFile 自定义镜像Tomcat9

 DockerFile 自定义镜像Tomcat9

 六、run

docker run -d -p 9080:8080 --name myt9 -v /czyuse/mydockerfile/tomcat9/test:/usr/local/apache-tomcat-9.0.30/webapps/test -v /czyuse/mydockerfile/tomcat9/tomcat9logs/:/usr/local/apache-tomcat-9.0.30/logs --privileged=true czytomcat9

七、验证

DockerFile 自定义镜像Tomcat9

 DockerFile 自定义镜像Tomcat9

 八、结合前述的容器卷将测试的web服务test发布

 DockerFile 自定义镜像Tomcat9

 DockerFile 自定义镜像Tomcat9

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://java.sun.com/xml/ns/javaee"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  id="WebApp_ID" version="2.5">
  
  <display-name>test</display-name>
 
</web-app>

DockerFile 自定义镜像Tomcat9

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
  </head>
  <body>
    -----------welcome------------
    <%="i am in docker tomcat self "%>
    <br>
    <br>
    <% System.out.println("=============docker tomcat self");%>
  </body>
</html>

DockerFile 自定义镜像Tomcat9

 DockerFile 自定义镜像Tomcat9

 DockerFile 自定义镜像Tomcat9

 修改 a.jsp

DockerFile 自定义镜像Tomcat9

刷新

 DockerFile 自定义镜像Tomcat9

 DockerFile 自定义镜像Tomcat9

 DockerFile 自定义镜像Tomcat9

 总结

DockerFile 自定义镜像Tomcat9

 

相关推荐