Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dockerizing Spring Boot Applications: Makings of a Better Docker Image

Dockerizing Spring Boot Applications: Makings of a Better Docker Image

Vedran Pavić

October 14, 2019
Tweet

More Decks by Vedran Pavić

Other Decks in Technology

Transcript

  1. 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
  2. +

  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. Q&A