编写dockerfile脚本文件名最好是DockerFile,build的时候可以省略-f参数
1、准备好tomcat、jdk安装包导入文件
2、编写DockerFile脚本
FROM centos:7.6
MAINTAINER cao<123@qq.com>
COPY readme.txt /usr/local/readme.txt
ADD jdk-8u291-linux-x64.tar.gz /usr/local/
ADD apache-tomcat-8.5.65.tar.gz /usr/local/
RUN yum -y install vim
ENV MYPATH /usr/local
WORKDIR $MYPATH
ENV JAVA_HOME /usr/local/jdk1.8.0_291
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-8.5.65
ENV CATALINA_BASH /usr/local/apache-tomcat-8.5.65
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
EXPOSE 8080
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、构建镜像
doucker build -t mytomcat .
4、启动镜像
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、本地测试
curl localhost:8080
6、发布项目(由于做了卷挂载,就可以直接在本地编写项目发布了)
本地的tomcat-webapp下放入需要搭建的项目测试即可