1、拷贝 jdk,tomcat,war包 到 项目目录下

2、查看目录结构 

cd /home/fresh/dockerbuild/

ll

-rw-r--r-- 1 root root 10420837 Sep 26 21:13 apache-tomcat-8.5.58.tar.gz
-rw-r--r-- 1 root root 549 Sep 26 21:49 Dockerfile
-rw-r--r-- 1 root root 2999158 Sep 26 21:25 fresh.war
-rw-r--r-- 1 root root 194151339 Sep 26 21:13 jdk-8u231-linux-x64.tar.gz
-rwxr-xr-x 1 root root 117 Sep 26 21:48 start.sh

3、 编写 Dockerfile

FROM centos:7

RUN mkdir /usr/local/java
ADD jdk-8u231-linux-x64.tar.gz /usr/local/java
ENV JAVA_HOME=/usr/local/java/jdk1.8.0_231
ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib/rt.jar
ENV PATH=$PATH:$JAVA_HOME/bin

RUN mkdir /usr/local/tomcat
ADD apache-tomcat-8.5.58.tar.gz /usr/local/tomcat
ENV CATALINA_HOME=/usr/local/tomcat/apache-tomcat-8.5.58
ENV PATH=$PATH:$CATALINA_HOME/bin

COPY fresh.war $CATALINA_HOME/webapps/

EXPOSE 8080
ENTRYPOINT ["/usr/local/tomcat/apache-tomcat-8.5.58/bin/catalina.sh","run"]

4、编写启动脚本

docker stop fresh && docker rm fresh
docker build -t fresh:v1 .
docker run --name fresh \
-p 8280:8080 \
-d fresh:v1

5、执行

chmod +x start.sh

./start.sh

 6、查看

CONTAINER ID        IMAGE      COMMAND                  CREATED           PORTS                     NAMES
c38b4c4bd91b fresh:v1 "/usr/local/tomcat/a…" 9 minutes ago 0.0.0.0:8280->8080/tcp fresh