Spring Boot 2.4 new features one-click build Docker image process detailed explanation

Spring Boot 2.4 new features one-click build Docker image process detailed explanation

background

In order to support Docker containerization during our development process, we generally use Maven to compile and package and then generate images, which can greatly improve the online efficiency, and can also quickly and dynamically expand capacity and quickly roll back, which is really convenient. The docker-maven-plugin plugin is designed to help us automatically generate images and push them to the warehouse through simple configuration in Maven projects.

spotify, fabric8

The two main plug-ins used here are spotify and fabric8, ... -Configure the Dockerfile through XML or mount an external Dockerfile to build an image by calling the Docker remote api

All containerization of the pig microservice platform is based on this construction

<plugin>
 <groupId>com.spotify</groupId>
 <artifactId>docker-maven-plugin</artifactId>
 ... -Configure the Dockerfile defined by XML or mount an external Dockerfile
</plugin>

<plugin>
 <groupId>io.fabric8</groupId>
 <artifactId>docker-maven-plugin</artifactId>
  ... -Configure the Dockerfile defined by XML or mount an external Dockerfile
</plugin>

Execute the corresponding plug-in cycle mvn docker:build && mvn docker:push

jib

The amount of code that actually changes each time a project is released is not large, especially the possibility of changes in the dependent jars is small. If the first two plug-ins are used to build the image, a full build will be performed each time, resulting in a waste of storage and bandwidth resources.

Jib is a tool for building images for Java applications released by Google in July 2018 (supporting Maven and Gradle). The advantage is that it can reuse the build cache, speed up the build, and reduce the transmission volume.

<!--Configure the Dockerfile through XML, which is essentially the same as the external Dockerfile -->
<plugin>
  <groupId>com.google.cloud.tools</groupId>
  <artifactId>jib-maven-plugin</artifactId>
</plugin>

mvn jib:dockerBuild

Problems with the above three solutions

In the actual development process, most spring boot projects build Dockerfiles in the same way, and do not need to be redefined through XML or external Dockerfiles.

The above plugins require a relatively good knowledge of Dockerfile definitions, which is not developer-friendly.

There is no good reason to use the Jar layering technology after Spring Boot 2.3.

Solution

Spring Boot 2.4 launched its own docker build tool integrated into the original spring-boot-maven-plugin. You only need to configure the corresponding target warehouse and host information to complete the image building.

insert image description here

The following configuration can complete the above figure. Without installing Docker on the development machine, the image is built through the Docker Remote API of 192.168.0.10 and published to the image warehouse of 192.168.0.20.

 <plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
    <image>
      <name>192.168.0.20/pig4cloud/${project.artifactId}</name>
      <!-- Automatically push after build is executed -->
      <publish>true</publish>
    </image>
    <!--Configure the build host information, no configuration is required for this machine-->
    <docker>
			<host>http://192.168.0.10:2375</host>
      <tlsVerify>false</tlsVerify>
      <publishRegistry>
        <username>username</username>
        <password>password</password>
        <url>192.168.0.20</url>
      </publishRegistry>
    </docker>
  </configuration>
</plugin>

Execute the following command to complete the image building and automatic release

mvn spring-boot:build-image

Other notes

Docker host configuration does not take effect

The node is configured as shown in the figure below ①, but ② reports an error indicating that the host is inconsistent

insert image description here

Check whether the $DOCKER_HOST environment variable is configured locally. After reading the source code, I found that this variable is read first.

⋊> ~ echo $DOCKER_HOST 11:07:51
tcp://172.17.0.111:2375

Network support

Intercepting some logs during the build process, the following requires downloading related dependencies of about 100M from GitHub, and this process is likely to fail. It is recommended to solve this problem by configuring a proxy or using a foreign ECS.

 :: Spring Boot :: (v2.4.0)
[INFO] > Running creator
[INFO] [creator] Downloading from https://github.com/bell-sw/Liberica/releases/download/8u275+1/bellsoft-jre8u275+1-linux-amd64.tar.gz
[INFO] [creator] JVMKill Agent 1.16.0: Contributing to layer
[INFO] [creator] Downloading from https://github.com/cloudfoundry/jvmkill/releases/download/v1.16.0.RELEASE/jvmkill-1.16.0-RELEASE.so
[INFO] [creator] Downloading from https://repo.spring.io/release/org/springframework/cloud/spring-cloud-bindings/1.6.0/spring-cloud-bindings-1.6.0.jar
[INFO] [creator] Verifying checksum
[INFO] [creator] 192.168.0.20/pig4cloud/demo:latest
[INFO]
[INFO] Successfully built image '192.168.0.20/pig4cloud/demo:latest'
[INFO] > Pushing image '192.168.0.20/pig4cloud/demo:latest' 100%
[INFO] > Pushed image '192.168.0.20/pig4cloud/demo:latest'
[INFO] BUILD SUCCESS

This is the end of this article about Spring Boot 2.4's new feature of building Docker images with one click. For more information about Spring Boot 2.4 building Docker images, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed explanation of the propagation characteristics of Spring things
  • Spring Boot 2.4 new features reduce memory usage by 95%
  • A comprehensive introduction to the new features of Spring 5
  • SpringBoot new features global lazy loading mechanism
  • Comprehensive analysis of the mechanism and characteristics of the Spring Security filter chain
  • Detailed explanation of the new feature of SpringBoot2.3: elegant shutdown
  • Spring MVC accepts form automatic encapsulation feature instance analysis
  • SpringBoot2.0 new features configuration binding full analysis
  • Introduction to new features of each version of Spring
  • Introduction to Spring Boot related features of Intellij IDEA 2017
  • A brief introduction to the new features of Spring Framework 5.0
  • Spring4 new features web development enhancement
  • Brief analysis of Spring 4 new features overview
  • Java 8 features supported by Spring 4
  • Java Spring 5 new features functional web framework detailed introduction
  • Detailed explanation of Spring factory features

<<:  Use mysql to record the http GET request data returned from the url

>>:  Testing of hyperlink opening target

Recommend

Introduction to the use of CSS3 filter attribute

1. Introduction When writing animation effects fo...

WeChat applet implements a simple dice game

This article shares the specific code of the WeCh...

Solution to Linux QT Kit missing and Version empty problem

Currently encountering such a problem My situatio...

Teach you to create custom hooks in react

1. What are custom hooks Logic reuse Simply put, ...

Using MySQL database in docker to achieve LAN access

1. Get the mysql image docker pull mysql:5.6 Note...

MySQL index principle and usage example analysis

This article uses examples to illustrate the prin...

A complete list of meta tag settings for mobile devices

Preface When I was studying the front end before,...

HTML tag meta summary, HTML5 head meta attribute summary

Preface meta is an auxiliary tag in the head area...

MySQL database green version installation tutorial to solve system error 1067

What is the difference between the green version ...

Tutorial on upgrading, installing and configuring supervisor on centos6.5

Supervisor Introduction Supervisor is a client/se...

Use standard dl, dt, dd tags to discard table lists

Now, more and more front-end developers are starti...

Detailed explanation of Nginx timeout configuration

I recently used nginx in a project, and used Java...

Angular Dependency Injection Explained

Table of contents Overview 1. Dependency Injectio...

Vue opens a new window and implements a graphic example of parameter transfer

The function I want to achieve is to open a new w...