SlideShare a Scribd company logo
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
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
A minimal HTTP server in Java
A minimal Dockerfile
[ Demo ]
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 ]
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?
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 ]
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
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
Dealing with memory limits
[ Demo ]
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+
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: uri.savelchev@zalando.fi
GitHub: https://github.com/alterrebe
Q&A

More Related Content

PPTX
Reducing latency on the web with the Azure CDN- TechDays NL 2014
PPTX
Reducing latency on the web with the Azure CDN - DevSum - SWAG
PPTX
Scalability at GROU.PS
PPTX
Drupal in the cloud with Windows Azure
PDF
deep learning in production cff 2017
PDF
How to Run TensorFlow Cheaper in the Cloud Using Elastic GPUs
PDF
Linux Block Cache Practice on Ceph BlueStore - Junxin Zhang
PDF
Hosting MongoDB & our experience with database as a service
Reducing latency on the web with the Azure CDN- TechDays NL 2014
Reducing latency on the web with the Azure CDN - DevSum - SWAG
Scalability at GROU.PS
Drupal in the cloud with Windows Azure
deep learning in production cff 2017
How to Run TensorFlow Cheaper in the Cloud Using Elastic GPUs
Linux Block Cache Practice on Ceph BlueStore - Junxin Zhang
Hosting MongoDB & our experience with database as a service

What's hot (17)

PDF
Open Datacentre
PDF
Breaking performance web rules
PDF
Big Data in a Public Cloud
PDF
Ceph, the future of Storage - Sage Weil
PDF
Infrastructure Management in GCP
PPTX
Migrating Existing Open Source Machine Learning to Azure
PDF
Ceph Goes on Online at Qihoo 360 - Xuehan Xu
PPTX
Ceph Day London 2014 - Best Practices for Ceph-powered Implementations of Sto...
PDF
Kubernetes training
PPTX
Heap Dump Analysis - AEM: Real World Issues
PDF
Fire dev ops - lightning talk from WrocLove.rb 2014
PPTX
NSBCon UK nservicebus on Azure by Yves Goeleven
PPTX
141204 upload
PPTX
OpenStack and Ceph case study at the University of Alabama
PPTX
R in Minecraft
PDF
Trends in DNN compression
PDF
2016-JAN-28 -- High Performance Production Databases on Ceph
Open Datacentre
Breaking performance web rules
Big Data in a Public Cloud
Ceph, the future of Storage - Sage Weil
Infrastructure Management in GCP
Migrating Existing Open Source Machine Learning to Azure
Ceph Goes on Online at Qihoo 360 - Xuehan Xu
Ceph Day London 2014 - Best Practices for Ceph-powered Implementations of Sto...
Kubernetes training
Heap Dump Analysis - AEM: Real World Issues
Fire dev ops - lightning talk from WrocLove.rb 2014
NSBCon UK nservicebus on Azure by Yves Goeleven
141204 upload
OpenStack and Ceph case study at the University of Alabama
R in Minecraft
Trends in DNN compression
2016-JAN-28 -- High Performance Production Databases on Ceph
Ad

Similar to Running JVM in Docker (20)

PDF
DCSF19 Docker Containers & Java: What I Wish I Had Been Told
PPTX
Build optimization mechanisms in GitLab and Docker
PDF
Java in a world of containers
PDF
Java in a World of Containers - DockerCon 2018
PPTX
Google jib: Building Java containers without Docker
PDF
Angular + JHipster - JHipster Conf
PDF
Leveraging Docker for Hadoop build automation and Big Data stack provisioning
PDF
Leveraging docker for hadoop build automation and big data stack provisioning
PDF
Dmytro Patkovskyi "Practical tips regarding build optimization for those who ...
PDF
Commit to excellence - Java in containers
PDF
Docker on a Diet
PDF
Java and Container - Make it Awesome !
PDF
Taking Docker to Production: What You Need to Know and Decide
PDF
Taking Docker to Production: What You Need to Know and Decide
PDF
Dockerfile best practices
PDF
Golang @ Tokopedia
PDF
Containerizing Python: Building efficient containers for Python applications
PPTX
CNCF Live Webinar: Low Footprint Java Containers with GraalVM
PPTX
A 1.5MB Java Container App? Yes you can!
PDF
Introduction to Docker storage, volume and image
DCSF19 Docker Containers & Java: What I Wish I Had Been Told
Build optimization mechanisms in GitLab and Docker
Java in a world of containers
Java in a World of Containers - DockerCon 2018
Google jib: Building Java containers without Docker
Angular + JHipster - JHipster Conf
Leveraging Docker for Hadoop build automation and Big Data stack provisioning
Leveraging docker for hadoop build automation and big data stack provisioning
Dmytro Patkovskyi "Practical tips regarding build optimization for those who ...
Commit to excellence - Java in containers
Docker on a Diet
Java and Container - Make it Awesome !
Taking Docker to Production: What You Need to Know and Decide
Taking Docker to Production: What You Need to Know and Decide
Dockerfile best practices
Golang @ Tokopedia
Containerizing Python: Building efficient containers for Python applications
CNCF Live Webinar: Low Footprint Java Containers with GraalVM
A 1.5MB Java Container App? Yes you can!
Introduction to Docker storage, volume and image
Ad

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Machine Learning_overview_presentation.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Approach and Philosophy of On baking technology
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Big Data Technologies - Introduction.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
DOCX
The AUB Centre for AI in Media Proposal.docx
Advanced methodologies resolving dimensionality complications for autism neur...
Spectral efficient network and resource selection model in 5G networks
MIND Revenue Release Quarter 2 2025 Press Release
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Machine Learning_overview_presentation.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Machine learning based COVID-19 study performance prediction
A comparative analysis of optical character recognition models for extracting...
20250228 LYD VKU AI Blended-Learning.pptx
Approach and Philosophy of On baking technology
Programs and apps: productivity, graphics, security and other tools
Big Data Technologies - Introduction.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Digital-Transformation-Roadmap-for-Companies.pptx
Spectroscopy.pptx food analysis technology
Mobile App Security Testing_ A Comprehensive Guide.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Encapsulation_ Review paper, used for researhc scholars
The AUB Centre for AI in Media Proposal.docx

Running JVM in Docker

  • 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 minimal HTTP server in Java
  • 5. 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 ]
  • 6. 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?
  • 7. 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 ]
  • 8. 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
  • 9. 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
  • 10. Dealing with memory limits [ Demo ]
  • 11. 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+
  • 12. 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: uri.savelchev@zalando.fi GitHub: https://github.com/alterrebe
  • 13. Q&A