The Jib plugin is an open-source tool developed by Google that allows developers to build Docker images without needing Docker installed or writing a Dockerfile. It integrates directly with Maven and Gradle, creating Docker images by layering dependencies and resources efficiently. Jib also supports both local and remote builds, sending images directly to registries like Docker Hub, while producing slightly larger images compared to traditional methods.
Jib plugin
This is an open-source tool from Google that doesn't require Docker to work. You also don't need to write a Dockerfile.
To use Jib, add the following to your pom.xml:
<build>
<plugins>
<plugin>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-maven-plugin</artifactid>
</plugin>
</plugins>
</build>
Building without Docker
One of the advantages of this plugin is building without installing Docker:
mvn compile jib:build
After the build, I searched for the image in my local storage. Then it hit me. In this mode, Docker is not used, so the image was sent to the registry on Docker Hub.
Pull the image and analyze it using dive:
The final weight came out to be 321 MB, which is 12 megabytes more than the previous method. Among them:
- 78 + 48 MB - Linux and various certificates.
- 140 MB - JDK.
- 55 MB - layer with release dependencies.
- 14 KB - layer with snapshot dependencies.
- 981 bytes - only resources. Resources folder.
- 22 KB - our written code.
Jib runs your image on behalf of the root user.
Similar to the Spring plugin, Jib separates dependencies into separate layers, but it goes even further and creates a separate layer for the resources folder. After all, resources are also rarely changed but can weigh a lot. For example, if you have many Liquibase migration scripts.
Building using Docker
For this, add the plugin as in the previous step but run a different command:
mvn compile jib:dockerBuild
The size and structure of the layers are no different from the image we built without Docker.
Conclusions on Jib
If you have an ARM processor, the image will still be built for amd64.
I have never used this plugin in projects, only heard about it, so I can't make any deep conclusions. It surprised me that it can work without Docker; sometimes this can be useful. But I don't see the point in using it when there is a Spring plugin available.