06--Docker自定义镜像Tomcat9
1. 创建目录 /zhengcj/mydockerfile/tomcat9
2.将jdk和tomcat的安装包拷贝到tomcat9下
3.在tomcat9目录下创建Dockerfile文件,并写以下命令
FROM centos MAINTAINER zhengcj<zhnen@qq.com> #把宿主机当前上下文的c.txt拷贝到容器/usr/local/路径下 COPY c.txt /usr/local/cincontainer.txt #把java与tomcat添加到容器中 ADD jdk-8u231-linux-x64.tar.gz /usr/local/ ADD apache-tomcat-9.0.41.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_231 ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.41 ENV CATALINA_BASE /usr/local/apache-tomcat-9.0.41 ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin #容器运行时监听的端口 EXPOSE 8080 #启动时运行tomcat # ENTRYPOINT ["/usr/local/apache-tomcat-9.0.41/bin/startup.sh" ] # CMD ["/usr/local/apache-tomcat-9.0.41/bin/catalina.sh","run"] CMD /usr/local/apache-tomcat-9.0.41/bin/startup.sh && tail -F /usr/local/apache-tomcat-9.0.41/bin/logs/catalina.out
4.构建镜像 docker build -t zhengcj/tomcat9 .
5.查看镜像
6.运行镜像,并创建数据持久化
docker run -d -p 8080:8080 --name myt9 -v /zhengcj/mydockerfile/tomcat9/test:/usr/local/apache-tomcat-9.0.8/webapps/test -v /zhengcj/mydockerfile/tomcat9/tomcat9logs/:/usr/local/apache-tomcat-9.0.8/logs --privileged=true zhengcj/tomcat9
7. 在目录/zhengcj/mydockerfile/tomcat9/test下创建test.html
<?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>
8.在目录/zhengcj/mydockerfile/tomcat9/test/WEB-INF下创建web.xml
<html> <head> <title>根目录</title> </head> <body> 测试页面 </body> </html>
9. 重启tomcat :docker restart 容器id