编写dockerfile脚本文件名最好是DockerFile,build的时候可以省略-f参数

1、准备好tomcat、jdk安装包导入文件

2、编写DockerFile脚本

  1. FROM centos:7.6
  2. MAINTAINER cao<123@qq.com>
  3. COPY readme.txt /usr/local/readme.txt
  4. ADD jdk-8u291-linux-x64.tar.gz /usr/local/
  5. ADD apache-tomcat-8.5.65.tar.gz /usr/local/
  6. RUN yum -y install vim
  7. ENV MYPATH /usr/local
  8. WORKDIR $MYPATH
  9. ENV JAVA_HOME /usr/local/jdk1.8.0_291
  10. ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
  11. ENV CATALINA_HOME /usr/local/apache-tomcat-8.5.65
  12. ENV CATALINA_BASH /usr/local/apache-tomcat-8.5.65
  13. ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
  14. EXPOSE 8080
  15. CMD /usr/local/apache-tomcat-8.5.65/bin/startup.sh && tail -F /usr/local/apache-tomcat-8.5.65/bin/logs/catalina.out

3、构建镜像

  1. doucker build -t mytomcat .

4、启动镜像

  1. docker run -d -p 9090:8080 --name cao_tomcat -v /home/cao/build/tomcat/test:/usr/local/apache-tomcat-8.5.65/webapps/test -v /home/cao/build/tomcat/tomcat_logs/:/usr/local/apache-tomcat-8.5.65/logs/ mytomcat

5、本地测试

  1. curl localhost:8080

6、发布项目(由于做了卷挂载,就可以直接在本地编写项目发布了)

本地的tomcat-webapp下放入需要搭建的项目测试即可