Docker makes tomcat image and deploys war package

Mock interview novice:

Requirement: There is a server without network, use docker to deploy war package, no tomcat image, and the time limit is 30 minutes.

Xiaobai: What are you doing deploying the war package without a network? Is it because the work is not saturated and you are too idle.

Me: Fool, blame me for not expressing clearly, because there is a dedicated VPN, and I cannot access the external network.

Xiaobai: blah blah... can't speak clearly

Me: Don’t be shy, tell me quickly, what is your thinking and how to do it

Xiaobai: Can you do Baidu... I think you are like Baidu, can you docker pull tomcat? No... then I won't.

Me: hhh, wouldn’t it be embarrassing if you met me, let me tell you.

train of thought

First deploy the war package, use our most commonly used web container tomcat, put the war package in the webapps directory, and automatically decompress and analyze it when starting tomcat. We can access through ip+port+path.

Xiaobai: I also thought of what you said, but the problem now is that the server cannot access the external network, and the tomcat image cannot be pulled directly through docker pull, so what should I do?

Don't worry, listen to me: we can create a mirror image on another computer, then transfer the mirror image and upload it to a server that cannot access the external network, and run it directly.

Pre-preparation:

1. Download the jdk package

2. Download the tomcat package (be sure to download the tar.gz package, the lesson of stepping on the pit)

3. Upload jdk and tomcat to the same directory. Then write the Dockerfile. The directory is /shiyi/mydocker (the directory can be customized)

4. Create a Dockerfile and write the content

Dockerfile file content

# vim Dockerfile

FROM centos
MAINTAINER shiyi<1282760680@qq.com>
# 会自动解压到指定目录,不需要人为去解压
ADD jdk-8u333-linux-x64.tar.gz /usr/local/
ADD apache-tomcat-8.5.81.tar.gz /usr/local/
RUN chmod a+x /usr/local
ENV MYPATH /usr/local
WORKDIR $MYPATH
ENV JAVA_HOME $MYPATH/jdk1.8.0_333
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME $MYPATH/apache-tomcat-8.5.81
ENV CATALINA_BASH $MYPATH/apache-tomcat-8.5.81
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
# 把war包放到webapps目录下
ADD xxxxs.war $CATALINA_HOME/webapps
EXPOSE 8080
WORKDIR $CATALINA_HOME/bin
RUN chmod a+x $CATALINA_HOME/bin/startup.sh
VOLUME ["$CATALINA_HOME/logs/","$CATALINA_HOME/webapps"]
# 注意:tail -F ,这里如果用小写的f,启动容器的时候打印完日志后会退出,用大写-F容器才会停留
CMD $CATALINA_HOME/bin/startup.sh && tail -F $CATALINA_HOME/logs/catalina.out

5. Make tomcat image according to Dockerfile

docker build -f /shiyi/mydocker/Dockerfile -t shiyitomcat:1.0 /shiyi/mydocker

If you see successful, it means the packaging is successful.
View image

docker images

start tomcat

docker run -itd -p 8080:8080 shiyitomcat:1.0

View the tomcat startup log

docker logs xxx(容器id)

Access: ip+port+path access project

Xiaobai, isn't it very simple...

Xiaobai: I’m going to run on the server without internet, don’t deploy it here! ! !

Just dump the mirror image, isn't it stupid?

6. Dump image

docker save -o mytomcat_image.docker mytomcat:1.0

Seven, restore the mirror image

docker load -i  mytomcat_image.docker mytomcat
I am Amnesia, an otaku who loves technology. If you have any questions about the article, you can point it out in the message. Welcome to leave a message. You can also add my personal WeChat to study together and make progress together!

insert image description here

Guess you like

Origin blog.csdn.net/qq_42216791/article/details/125784203