close

Creating Docker images with Spring Boot 2.3.0.M1

Spring Boot 2.3.0.M1 has just been released and it brings with it some interesting new features that can help you package up your Spring Boot application into Docker images. In this blog post we’ll take a look at the typical ways developers create Docker images, and show how they can be improved by using these new features.

Common Docker Techniques

Although it’s always been possible to convert the fat jars produced by Spring Boot into Docker images, it’s pretty easy to make less than optimal results. If you do a web search for "dockerize spring boot app", the chances are high you’ll find an article or blog post suggesting you create a dockerfile that looks something like this:

FROM openjdk:8-jdk-alpine
EXPOSE 8080
ARG JAR_FILE=target/my-application.jar
ADD ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

Whilst this approach works fine, and it’s nice and concise, there are a few things that are sub-optimal.

The first problem with above file is that the jar file is not unpacked. There’s always a certain amount of overhead when running a fat jar, and in a containerized environment this can be noticeable. It’s generally best to unpack your jar and run in an exploded form.

The second issue with the file is that it isn’t very efficient if you frequently update your application. Docker images are built in layers, and in this case your application and all its dependencies are put into a single layer. Since you probably recompile your code more often than you upgrade the version of Spring Boot you use, it’s often better to separate things a bit more. If you put jar files in the layer before your application classes, Docker often only needs to change the very bottom layer and can pick others up from its cache.

Two new features are introduced in Spring Boot 2.3.0.M1 to help improve on these existing techniques: buildpack support and layered jars.

Read more

This Week in Spring - January 21st, 2020

Hi, Spring fans! It’s 6 am Tuesday, January 21st, 2020, and I’m buckled in and ready to take off for Atlanta, Georgia (by way of Denver, Colorado…), where I’ll be speaking at the Atlanta Java User Group tonight! I’m so looking forward to seeing everyone there. It’s my first JUG appearance in the new year, too!

So, let’s get to it!

Read more

This Week in Spring - January 14th, 2020

Hi, Spring fans! What a week! I have … nothing… happening this week! You know why? I had jury duty for which I was summonsed in mid-2019. I had to postpone it since I was on the road. I finally report to the court to serve as a juror for some trial unknown, this month, January 2020, and I was there… for maybe two hours. I was excused! You should definitely do your civic duty, of course. But, it was awesome to have it over and done within a few hours. I had blocked out the entire week, just in case. So, now I’m working on my Reactive Spring book, writing a ton of code to support improvements to the production pipeline of my podcast, and so much more.

Read more

Reactive BookStore Service Broker

Happy belated new year to the Spring community! As we start another amazing year of development and advancement within the Spring project ecosystem, I want to share with you an updated sample application that represents some of the progress we have made across the portfolio to support a Reactive programming model.

The BookStore Service Broker sample application has been updated to demonstrate the integration of several of the various Spring projects, including Spring Cloud Open Service Broker, Spring Data, Spring Security, Spring HATEOAS, and of course Spring WebFlux and Spring Boot. All of these projects have GA versions that include Reactive support and are ready for production in your own applications and services.

Read more

This Week in Spring - 9th Anniversary Edition - January 7, 2020

Hi, Spring fans! Welcome to another installment of This Week in Spring! This is also the 9th anniversary of the This Week in Spring blog series. I started it the first Tuesday after the new year in January 2011. NINE years is a long time, and it’s been - and continues to be - a ton of fun.

I’ve never missed an installment - every Tuesday for almost a decade, come heck or high water - I get this done. It’s always on Tuesday, my time - whatever time that is. If I’m in Tokyo or Shanghai or Sydney then the installment may very well post sometime in most people’s Monday, or if I’m in California or Hawaii or South America, then it might be posted sometime early into most people’s Wednesday. But it’s always my Tuesday. Some times, I’ve had to cheat and apply the Hawaii rule: it’s still Tuesday if it’s still Tuesday in Hawaii! But, it’s always Tuesday. Things have gotten easier for me. Nowadays, plenty of airplanes have Wi-Fi. And, our blog software now supports scheduled posts. So, almost no reason I should ever miss an installment unless I’m very busy.

Read more

A Bootiful Podcast: Spring Boot and Spring Cloud co-founder Dr. Dave Syer

Hi, Spring fans! In this episode, Josh Long talks to the one, the only, the inimitable, the amazing, his hero, the good Dr. Dave Syer, Spring Framework committer, former Spring Batch lead, former Spring Security OAuth lead, co-founder of both Spring Boot and Spring Cloud, etc. Statistically, if you’re using Spring today, you’re probably using code he wrote. This episode was recorded at SpringOne Platform 2019. Happy new year, and enjoy!

Read more

This Decade in Spring - Happy New Year Edition - December 31, 2019

Hi, Spring fans, and HAPPY NEW YEAR! Welcome to another, extra-special installment of This Week in Spring. Normally, when writing the first post after or before the new year, I chronicle the most important moments in the last year. This year, seeing as we’re about to tip the scales and embark upon not just a new year but a new decade, I’m going to do my level headed best to distill the biggest and the best for the Spring ecosystem in the last decade. The problem I face in writing this isn’t in coming up with things to mention, it’s in limiting the number of things I mention!

Read more