Using Jib to Build Docker Images for Spring Boot 2 Applications

Posted on
Spring Boot Docker Gradle Kotlin Jib Plugin Workbench

If you want to create a Docker image from your Spring Boot 2 application you can use various plugins for Gradle or Maven. They all have in common that the application itself will be added as a single layer containing the full jar including all dependencies. For a typical Spring Boot 2 application this means, that for each build an image layer of at least 60MB has to be pushed to the registry. This is one disadvantage compared to Jakarta EE applications which result in much smaller artifacts (Adam Bien: JAVA EE 7 + THIN WARS + DOCKER = GREAT PRODUCTIVITY).

The (Jib Project) initiated by Google follows another approach to help minimize what has to be rebuild and deployed for a Java application. The plugin will split the fat jar generated by Spring Boot into classes, resources and libraries (dependencies) and use them for separate layers of the container. Therefore changing the application will result in a much smaller image layer to be sent to the Docker registry. In a very basic application this results in a layer of less then 5kB.

To demonstrate the usage of the Jib plugin I’ve setup project at my GitHub.