Build spring boot container images without writing docker files using cloud native build packs

Photo by Aleksandar Pasaric from Pexels
In my previous blog post I have shared how we can create optimized docker images for spring boot applications. With the release of spring boot 2.3 spring has introduced buildpack support to both maven and gradle directly. What buildpacks simply does is it convert your jar file into a container image without a docker file. You only need to run below commands to build the container image.


mvn spring-boot:build-image


gradle bootBuildImage

Surprisingly that's pretty much it, your container image is now build for you and now you don't need to maintain your docker files separately, also it's well optimized.  Let's see the example below, I'm using my previous example and only change that I have done is, deleted the docker file. 

1) Run: mvn spring-boot-build-image 

2) Check the docker images, you will see your docker image build by buildpack.

3) Inspect the docker image using dive , as you can see the image is more layered than our previous build.
4) Run the container, just to make sure our docker container is working fine. Run the docker image and execute the curl command.

docker run -d -p 8080:8080 rest-localization:v1
curl -X GET -H "Accept-Language: zh" 'http://localhost:8080/api/v1/menu'

That's it for this quick blog post, I just wanted to show you guys this feature in spring boot. As usual source code can be found in

References & Useful Readings.