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

Running JVM in Docker

Running JVM in Docker

A talk at the Helsinki JUG meetup on 17.05.2018

Uri Savelchev

May 17, 2018
Tweet

Other Decks in Technology

Transcript

  1. Running JVM in Docker Just scratching the surface © 2018

    Zalando SE / Uri Savelchev This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License
  2. Agenda 1. The quick way to dockerize your Java app

    2. Reduce the container image footprint ◦ Alternative base images ◦ Jigsaw and native JRE 3. Setting memory limits ◦ Out of the box default is wrong ◦ Using cgroups and new JVM features ◦ JVM ergonomics
  3. A problem • The JAR file size is 3.6 KB

    • The Docker image size is 726 MB • Is it something weird? Why should I care about it? • Larger image - slower deployment • More unused stuff - more room for exploits • Technical excellence [ Demo ]
  4. So far we have shrunk the image by factor “9”!

    Docker image Local tag Size OpenJDK8 + Debian Stretch default 726 MB OpenJRE8 + Debian Strech “Slim” slim 205 MB OpenJRE8-musl + Alpine ultraslim 82 MB Can we do better?
  5. Project Jigsaw • Module system for Java • Available starting

    from Java9 • Allows to build native JRE Special thanks to Mikko Värri - https://github.com/vmj/http-server [ Demo ]
  6. Got image smaller by factor 20 Docker image Local tag

    Size OpenJDK8 + Debian Stretch default 726 MB OpenJRE8 + Debian Strech “Slim” slim 205 MB OpenJRE8-musl + Alpine ultraslim 82 MB Jigsaw + OpenJRE11-musl + Alpine modular 35 MB Jigsaw + OpenJRE11-musl + Alpine - add Jolokia modular-jolokia 41 MB
  7. Conclusions 1. Using Alpine allows to get images lesser than

    hundred megs 2. Jigsaw and modularization allows to make it even smaller, but a. You have to use Java9+ b. You have to build the native JRE inside Docker c. It’s more complex and therefore more fragile
  8. Conclusions 1. Don’t rely upon the default memory settings in

    Docker! 2. Use cgroups-provided value instead of environment variable 3. The default ergonomics is not good for Docker a. Either compute the memory limit yourself b. Or use -XX:MaxRAMPercentage=N for Java10+
  9. References • Materials for Helsinki Java meetup talk • A

    Java HTTP server in 35MB Docker image • Java inside Docker: What you must know to not FAIL Email: [email protected] GitHub: https://github.com/alterrebe
  10. Q&A