Three Maven Ways to Turn Your Spring Boot App into a Docker Image

Learn how to package a Spring Boot application into a Docker image using three Maven plugins—spring-boot-maven-plugin's build-image, Google's jib-maven-plugin, and the dockerfile-maven-plugin—complete with setup steps, command examples, and tips for container testing.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
Three Maven Ways to Turn Your Spring Boot App into a Docker Image

This article introduces three techniques to build a Docker image for a Spring Boot application using Maven.

#1 Spring Boot Maven Plugin build-image

The Spring Boot Maven plugin provides a built‑in build-image goal that creates a Docker image without requiring a Dockerfile. Simply run: mvn spring-boot:build-image After the build succeeds, run the container to verify:

docker run -p 9090:8080 -t demo-application:0.0.1-SNAPSHOT

Note that the host port mapped is 9090.

#2 jib-maven-plugin

Jib is a Maven (and Gradle) plugin that builds Docker images without needing a local Docker installation, making it ideal for CI pipelines. Execute:

mvn compile com.google.cloud.tools:jib-maven-plugin:2.3.0:dockerBuild

Then test the image with:

docker run -p 9091:8080 -t demo-application:0.0.1-SNAPSHOT

The host port mapped here is 9091.

#3 dockerfile-maven-plugin

This plugin requires a Dockerfile placed in the project root alongside pom.xml. The Dockerfile references the built JAR via the JAR_FILE property, which must be configured in pom.xml.

Running the standard Maven package command builds the image automatically: mvn package Test the resulting container with:

docker run -p 9092:8080 -t demo-application:0.0.1-SNAPSHOT

The host port mapped is 9092.

Conclusion

Among the three methods, the native Spring Boot approach is the simplest, requiring no extra configuration. Jib stands out for its ability to build images without a local Docker daemon, while the dockerfile‑maven‑plugin, although more involved, offers the most control and reliability.

References

jib-maven-plugin

dockerfile-maven-plugin

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DockermavenSpring BootJibdockerfile-maven-plugin
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

0 followers
Reader feedback

How this landed with the community

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.