Slide 1

Slide 1 text

Dockerizing Spring Boot Applications Makings of a Better Docker Image VEDRAN PAVIĆ

Slide 2

Slide 2 text

About Me – Vedran Pavić Java Engineer & Team Lead at Infinum Check out what we do at https://infinum.co Spring user for over a decade Contributor to Spring projects since 2015 Collaborator with Spring Security team – Spring Session committer since 2016

Slide 3

Slide 3 text

+

Slide 4

Slide 4 text

Benefits of Dockerizing More control over runtime - JVM Consistency across different environments Eliminate works on my machine problems Standardized packaging and distribution Use Docker registry for applications as we do Maven repository for libraries Build once, deploy everywhere – separation between build/release and deployment phases

Slide 5

Slide 5 text

Demo: four-liner

Slide 6

Slide 6 text

Four-liner approach Executable JAR pitfalls Limitations with some APIs (e.g. java.nio.file.Path) Performance implications – check out blog post by Dave Syer: https://spring.io/blog/2018/12/12/how-fast-is-spring Make JAR, not WAR – what actually matters more is how you run it No reuse, no caching – slow pushes and pulls Everything’s in the same layer

Slide 7

Slide 7 text

Demo: layered image

Slide 8

Slide 8 text

Layered image approach Addresses shortcomings of four-liner approach Requires unpacking of executable JAR Build plugin to handle all of this? Several build plugin available, however unpacking is regularly an extra step

Slide 9

Slide 9 text

Enter Google’s Jib Opinionated view on building containers Goals: fast, reproducible, daemonless Plugins for both Gradle & Maven Still relatively new 0.1.0 in Feb 2018, 1.0.0 in Jan 2019

Slide 10

Slide 10 text

Demo: Jib plugin

Slide 11

Slide 11 text

Reproducible builds matter Read more at https://reproducible-builds.org Jib handles Docker image side of reproducibility But your application needs to play nice too! Remove non-deterministic behavior from your build Enemy of the state: java.util.Properties#store

Slide 12

Slide 12 text

Demo: Reproducible image

Slide 13

Slide 13 text

Spring 5.2 improvements Support for writing properties in repeatable manner https://github.com/spring-projects/spring-framework/issues/23018 Upcoming Spring Boot 2.2 will leverage those

Slide 14

Slide 14 text

Demo: Spring Boot 2.2 improvements

Slide 15

Slide 15 text

Q&A

Slide 16

Slide 16 text

Thanks! @vedran_pavic github.com/vpavic speakerdeck.com/vpavic