Cloud Native 8 min read

Effortless Docker Image Creation for Spring Boot: Maven Plugins vs Jib

This article compares Maven Docker plugins (spotify, fabric8) and Jib, highlights their drawbacks for Spring Boot projects, and shows how Spring Boot 2.4's built‑in docker support simplifies image building and publishing via the spring‑boot‑maven‑plugin.

Java Architecture Diary
Java Architecture Diary
Java Architecture Diary
Effortless Docker Image Creation for Spring Boot: Maven Plugins vs Jib

Background

During development we often use Maven to compile and package, then generate Docker images, which improves deployment speed, scaling, and rollback. The docker‑maven‑plugin helps automatically build and push images from a Maven project.

spotify, fabric8

Two common plugins are

spotify

and

fabric8

, which define a Dockerfile via XML or mount an external Dockerfile and invoke the Docker remote API to build the image.

pig micro‑service platform [1] is the basis for all containerization.

<code>&lt;plugin&gt;
  &lt;groupId&gt;com.spotify&lt;/groupId&gt;
  &lt;artifactId&gt;docker-maven-plugin&lt;/artifactId&gt;
  ...
&lt;/plugin&gt;

&lt;plugin&gt;
  &lt;groupId&gt;io.fabric8&lt;/groupId&gt;
  &lt;artifactId&gt;docker-maven-plugin&lt;/artifactId&gt;
  ...
&lt;/plugin&gt;
</code>

Run the plugin lifecycle with

mvn docker:build && mvn docker:push

.

jib

When code changes are small, using the previous plugins rebuilds the whole image, wasting storage and bandwidth.

Jib, released by Google in July 2018, builds Java images (Maven/Gradle) by reusing build cache, speeding up builds and reducing image size.

<code><!-- configuration via XML ... -->
&lt;plugin&gt;
    &lt;groupId&gt;com.google.cloud.tools&lt;/groupId&gt;
    &lt;artifactId&gt;jib-maven-plugin&lt;/artifactId&gt;
&lt;/plugin&gt;

mvn jib:dockerBuild
</code>

Problems with the three approaches

Most Spring Boot projects share the same Dockerfile; redefining it via XML or external Dockerfile is unnecessary.

The plugins require knowledge of Dockerfile syntax, which is not developer‑friendly.

Spring Boot 2.3+ provides layered JARs, reducing the need for custom Dockerfiles.

Solution

Spring Boot 2.4 introduces its own Docker build support integrated into

spring-boot-maven-plugin

. Configuring the target registry and host is enough to build the image.

With the configuration below, the image can be built on a development machine without Docker installed, using Docker Remote API at

192.168.0.10

and publishing to the registry at

192.168.0.20

.

<code>&lt;plugin&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
    &lt;configuration&gt;
        &lt;image&gt;
            &lt;name&gt;192.168.0.20/pig4cloud/${project.artifactId}&lt;/name&gt;
            &lt;publish&gt;true&lt;/publish&gt;
        &lt;/image&gt;
        &lt;docker&gt;
            &lt;host&gt;http://192.168.0.10:2375&lt;/host&gt;
            &lt;tlsVerify&gt;false&lt;/tlsVerify&gt;
            &lt;publishRegistry&gt;
                &lt;username&gt;username&lt;/username&gt;
                &lt;password&gt;password&lt;/password&gt;
                &lt;url&gt;192.168.0.20&lt;/url&gt;
            &lt;/publishRegistry&gt;
        &lt;/docker&gt;
    &lt;/configuration&gt;
&lt;/plugin&gt;
</code>

Run

mvn spring-boot:build-image

to build and automatically push the image.

Other notes

Docker host configuration not effective

Even after setting the node in the UI, an error shows host mismatch; check the $DOCKER_HOST environment variable, which takes precedence.

<code>echo $DOCKER_HOST
tcp://172.17.0.111:2375
</code>

Network support

During build, large dependencies (~100 MB) are downloaded from GitHub and may fail; use a proxy or an overseas ECS to resolve.

<code>:: Spring Boot :: (v2.4.0)
[INFO]  > Running creator
[INFO]      [creator]  Downloading from https://github.com/bell-sw/Liberica/... 
[INFO]      [creator]  JVMKill Agent 1.16.0: Contributing to layer
[INFO]      [creator]  Downloading from https://github.com/cloudfoundry/jvmkill/... 
[INFO]      [creator]  Downloading from https://repo.spring.io/release/... 
[INFO]      Verifying checksum
[INFO]      192.168.0.20/pig4cloud/demo:latest
[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
</code>

References

pig micro‑service platform: https://gitee.com/log4j/pig

Spring Boot 2.4 Docker documentation: https://docs.spring.io/spring-boot/docs/2.4.0/maven-plugin/reference/htmlsingle/#build-image-example-publish

cloud-nativeDockermavencontainerizationSpring BootJib
Java Architecture Diary
Written by

Java Architecture Diary

Committed to sharing original, high‑quality technical articles; no fluff or promotional content.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.