Preface In Java programming, most applications are built based on Maven, and the delivered results are mostly in the form of Tomcat war packages. Therefore, it is necessary to build a basic image based on Maven and Tomcat. It can not only help us improve the efficiency of our daily independent experimental research and analysis, but also reduce operation and maintenance to a certain extent, reduce the complexity of writing Dockerfile, and improve the overall project delivery efficiency. 1. Create a compilation directory mkdir -p build_docker cd build_docker vim Dockerfile 2. Write Dockerfile First, we select the officially maintained maven:3.3.3 image as the base image, and then add Tomcat support on this basis. FROM maven:3.3.3 If you like the speed of domestic warehouses, you can also choose Alibaba's maven:3-jdk-8. FROM registry.cn-hangzhou.aliyuncs.com/acs/maven:3-jdk-8 Secondly, set Tomcat-related environment variables and add them to the system PATH variable so that Tomcat's startup script can be directly accessed in the Shell. ENV CATALINA_HOME /usr/local/tomcat ENV PATH $CATALINA_HOME/bin:$PATH RUN mkdir -p "$CATALINA_HOME" WORKDIR $CATALINA_HOME Third, add Tomcat GPG-KEY, which is used to verify whether the file is correct after Tomcat downloads it. The following keyid data comes from the official Tomcat-8. RUN gpg --keyserver pool.sks-keyservers.net --recv-keys \ F22C4FED \ 86867BA6 \ E86E29AC \ 307A10A5 \ 564C17A3 \ 0x7C037D42 \ 0BECE548 \ 5E763BEC \ 2F6059E7 \ 288584E7 \ 4B6FAEFB \ 286BACF1 \ 731FABEE \ 461B342D \ 0D498E23 \ DC3D1B18 \ D63011C7 \ 30480593 Fourth, set the Tomcat version variable. You can pass in the corresponding parameters to change the Tomcat version during the build. Because the Java version that the maven:3.3.3 image depends on is 1.8, we also choose the 8.X version for Tomcat. Maintaining compilation consistency can maximize the performance of Tomcat. Here we choose the latest version: 8.5.45 Then use curl to download, decompress after verification, and delete the redundant bat script. (This script is only used in Windows environment and is useless in Linux/Mac images) ENV TOMCAT_VERSION 8.5.45 ENV TOMCAT_TGZ_URL https://www.apache.org/dist/tomcat/tomcat-8/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz RUN set -x \ && curl -fSL "$TOMCAT_TGZ_URL" -o tomcat.tar.gz \ && curl -fSL "$TOMCAT_TGZ_URL.asc" -o tomcat.tar.gz.asc \ && gpg --verify tomcat.tar.gz.asc \ && tar -xvf tomcat.tar.gz --strip-components=1 \ && rm bin/*.bat \ && rm tomcat.tar.gz* Fifth, expose Tomcat's default port 8080 and specify a script to be executed when the container based on this image is started. This script is the Tomcat startup script. EXPOSE 8080 CMD ["catalina.sh", "run"] 3. Build the image docker build -t base-maven-tomcat . That's it, done. Attachment: Complete Dockerfile file FROM maven:3.3.3 ENV CATALINA_HOME /usr/local/tomcat ENV PATH $CATALINA_HOME/bin:$PATH RUN mkdir -p "$CATALINA_HOME" WORKDIR $CATALINA_HOME RUN gpg --keyserver pool.sks-keyservers.net --recv-keys \ F22C4FED \ 86867BA6 \ E86E29AC \ 307A10A5 \ 564C17A3 \ 0x7C037D42 \ 0BECE548 \ 5E763BEC \ 2F6059E7 \ 288584E7 \ 4B6FAEFB \ 286BACF1 \ 731FABEE \ 461B342D \ 0D498E23 \ DC3D1B18 \ D63011C7 \ 30480593 ENV TOMCAT_VERSION 8.5.45 ENV TOMCAT_TGZ_URL https://www.apache.org/dist/tomcat/tomcat-8/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz RUN set -x \ && curl -fSL "$TOMCAT_TGZ_URL" -o tomcat.tar.gz \ && curl -fSL "$TOMCAT_TGZ_URL.asc" -o tomcat.tar.gz.asc \ && gpg --verify tomcat.tar.gz.asc \ && tar -xvf tomcat.tar.gz --strip-components=1 \ && rm bin/*.bat \ && rm tomcat.tar.gz* EXPOSE 8080 CMD ["catalina.sh", "run"] The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: How to integrate the graphic verification code component into the Ant Design Pro login function
Solution 1: Use conditional import in HTML docume...
The pop-up has nothing to do with whether your cur...
When making a website, I found that video files, s...
Overview It is usually not what we want to presen...
1. Run fonts, open the font folder, and find the ...
Table of contents 1. User created script 2. Word ...
Table of contents Spring Boot Docker spring-boot-...
This article deploys Jenkins+Maven+SVN+Tomcat thr...
This article records the installation and configu...
Importing data with incorrect MySQL character set...
introduction: There are a lot of information and ...
1. Browser rendering mode and doctype Some web pa...
Table of contents The role of foreign keys mysql ...
How to declare a cursor in mysql: 1. Declare vari...
Due to business needs, there are often rush purch...