Let’s get started with Spring Boot Docker Image Creation.

Jayesh Patel
Ula Engineering
Published in
3 min readMay 29, 2020

The release of Spring Boot 2.3 has brought with it some cool new features like Java 14 support, Graceful Shutdown, Liveness and Readiness probes, Docker Image Creation, etc.

In this blog post, we’ll discuss how developers can create Docker images using Spring.

Prerequisites:

  • Basic Understanding of Spring Boot and Docker
  • Docker Daemon
  • A Bash-Like Shell

Let’s take a look at how convenient it is to create docker images using spring. I’m using Gradle but it’s just as easy to do with Maven.

First, create a new Spring Boot project using start.spring.io and add a dummy endpoint for testing your functionality.

Adding dummy endpoint for testing.

Now simply run one of the below commands based on your project type.

$ ./gradlew bootBuildImage

or if you’re using maven:

$ ./mvnw spring-boot:build-image

It will take a little time to run the first time around, but subsequent calls will be quicker. You should expect to see something like this in the build logs:

bootBuildImage Success

Your docker image listing should be listing these entries by now. (Please ignore the 40 years ago created date it’s a weird bug.)

Image Size

Run spring-boot-docker image in detached mode, hit your endpoint, and voila! You can see your application greeting the Universe!

Ah, what sorcery is this! Utilizing it, you could quickly deploy your local application to the production environment and enjoy the same level of consistency. You could also use Spring Boot Devtools with this, but you gotta say your goodbyes to Immutable Containers.

Although this is what spring offers out of the box, you can also customize the image creation process also reduce the size of the image being created by it.

This post answers how we can leverage Spring Boot Docker Image creation functionality to create a docker image. In the next post, we’ll take a deeper dive into the workings of this functionality.

--

--

Jayesh Patel
Ula Engineering

I'm a backend developer turned technical writer. I share insider tips & guides on software development and trends in logistics tech