1. Prepare the Spring Boot project Simple, skip 2. Perform relevant configurationMany blogs on the Internet emphasize that you need to manually configure the pom.xml to enable layered packaging: <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <!--Enable tiered compilation support--> <layers> <enabled>true</enabled> </layers> </configuration> </plugin> </plugins> </build> In version 2.3.x, it is a new feature and needs to be manually configured and enabled. However, the current Spring Boot version (using version 2.6.1) does not require manual configuration and supports this feature by default. (According to some blogs, it is enabled by default after version 2.4.x) The current official documentation (version 2.6.0) also states that it is supported by default, but manual configuration is required only when this feature is not needed: The repackaged archive includes the <project> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <layers> <enabled>false</enabled> </layers> </configuration> </plugin> </plugins> </build> </project> 3. package Execute In fact, the essence is to use the repackage of the spring-boot-maven plug-in to get the complete jar package containing dependencies and the original jar package (the suffix .original is automatically added) classpath.idx
layers.idx
Verify again: Layered information ok 4. DockerfileThe Dockerfile file is also relatively conventional. It just uses the jarmode command to decompress the jar package before packaging the image. Then, during the packaging process, different layers are copied in sequence, and the application layer with the greatest possibility of change is placed at the end. In this way, the previous layers that have no changes can directly use Docker's cache to improve packaging efficiency.
5. Application modification & dive analysis In fact, if you only package the image once, the advantages of layering will not be reflected, so you need to modify some content and then package it again (or multiple times, but the essence is the same, so only modify it once here) Re-pack the jar package and re-image, so that two images are obtained: Use dive to analyze the two images: It can be found that until the application layer (application/application/) is changed, the Id and Digest of the layers on both sides are exactly the same, so these layers can be reused, and the same layer will only be stored individually in the docker directory, which can greatly reduce the time for container compilation and push. This is the end of this article about the practice and analysis of Spring Boot layered packaging Docker image. For more relevant Spring Boot layered packaging Docker image content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: In-depth understanding of the seven communication methods of Vue components
1. About Registry The official Docker hub is a go...
1. Install MySQL This article is installed via AP...
introduce A chart is a graphical representation o...
Just like code, you can add comments to tables an...
When we are writing projects, we often encounter ...
Table of contents 1. Use the a tag to preview or ...
This article uses examples to describe various co...
Table of contents Preface 1. typeof 2. instanceof...
Recently, there have been many database-related o...
1. Command Introduction The seq (Sequence) comman...
Preface I recently made a fireworks animation, wh...
1. First, let's review the relevant knowledge...
Table of contents 1. Routing related objects 2. L...
After MySQL is installed, you can verify whether ...
This article shares the specific code of JavaScri...