Cover Image for Let’s get started with Spring Boot Docker Image Creation

Let’s get started with Spring Boot Docker Image Creation

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:

Ready with the prerequisites? 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 and add a dummy endpoint for testing your functionality.

1644mr9fwspcnixa3u4p.png

20v2q8dbb0xdbaqa4hmz.png

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

2b4ld3t02mqo6dqd7qtc.png

or if you’re using maven:

cqvt82v5uragyoq3z3dw.png

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:

6qr9629aogb9vzeyahqf.png

r6gic7x8hywbfqwiitip.png

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

3jr7y88qd9il90tzwasg.png

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

pzakpq014c2xxyjdflj0.png

Ah, what sorcery is this! Utilising 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 Dev-tools with this, but you gotta say your goodbyes to Immutable Containers.

Although this is what spring offers out of the box, you can also customise 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 working of this functionality.

Related Blogs