## 1. Preface

Jib is a class library developed by Google to build Docker and OCI images of Java applications directly, provided as Maven and Gradle plugins. The best part is that it can be built without the Docker daemon, i.e. you don’t have to install the docker daemon on your computer! Although Spring Boot 2.3.0.RELEASE has already been released with the ability to build images, I couldn’t resist trying Jib.

## 2. Docker build process and Jib’s build process

Contrast the build process of these two.

The Docker build process requires us to first type the project into Jar and then write a Dockerfile and then use the Docker build feature to build the image and run the container. The process is as follows.

And Jib is built like this.

As a Java developer, instead of caring about all kinds of extraneous commands and operations, you only need to focus on Java, and efficient and stable as well as reusable incremental builds. Why is Jib so fast and efficient?

Traditionally, Java applications are built as a single image layer along with the application Jar, whereas Jib’s build strategy divides Java applications into multiple layers for more granular incremental builds. When changing code, only the changes are rebuilt, not the entire application.

## 3. Jib Building Spring Boot Applications

Next I will show how to image the Spring Boot application and upload it to the Dockerhub repository.

Using the Maven project as an example, we just need to introduce the Jib Maven plugin in pom.xml. By default Jib will upload our image to Google’s gcr.io repository, in practice we will upload our image to a private repository, so we need to add some personalized configuration. Here I will use dockerhub repository as an example to add some personalized configuration.

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26   com.google.cloud.tools jib-maven-plugin 2.4.0 amazoncorretto:8 daxus/${project.name} felordcn yourpassword${project.version} 

Then execute mvn clean compile jib:build in the root of the project and you’re done.

It is also possible to simply introduce the Jib plug-in.

 1 2 3 4 5   com.google.cloud.tools jib-maven-plugin 2.4.0 

Only our command will be a bit more complex and will require specifying some necessary parameters, e.g.

 1 2 3 4  mvn clean compile jib:build \ -Djib.to.image=myregistry/myimage:latest \ -Djib.to.auth.username=$USERNAME \ -Djib.to.auth.password=$PASSWORD 

For more custom commands, please refer to the official documentation: