DEV Community

Jayesh Patel
Jayesh Patel

Posted on • Originally published at Medium

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:

  • Basic knowledge of Spring Boot and Docker
  • Docker Daemon
  • Bash like Shell

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 start.spring.io and add a dummy endpoint for testing your functionality.

Alt Text

Alt Text

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

Alt Text

or if you’re using maven:

Alt Text

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:

Alt Text
Alt Text

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

Alt Text

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

Hello 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 working of this functionality.

Top comments (0)