SlideShare a Scribd company logo
A 1.5MB Java Container App? Yes you can!
Shaun Smith
Senior Director
Oracle Labs—GraalVM
@shaunMsmith
Copyright © 2022, Oracle and/or its affiliates
2
Let’s start at the end!
Copyright © 2022, Oracle and/or its affiliates
3 Photo by 愚木混株 cdd20 on Unsplash
Hello World
Copyright © 2022, Oracle and/or its affiliates
4
GraalVM Enterprise Native Image—Ahead-of-time compiler & runtime
Copyright © 2022, Oracle and/or its affiliates
5
Windows
Executable
MacOS
Executable
Linux
Executable
.class
.jar
.class
.jar
Copyright © 2022, Oracle and/or its affiliates
6
Copyright © 2022, Oracle and/or its affiliates
7
Demo
1.5 MB Hello World Container
Copyright © 2022, Oracle and/or its affiliates
8
231
1.5
0
50
100
150
200
250
JDK / Distroless Java GraalVM Native Image / Scratch
JVM vs GraalVM Native Image (MB)
231 MB Container
• Minimal JDK with JVM required libs using
Distroless Java 17
1.5 MB Container
• Only needed code
• Only needed JDK
• Required libs statically linked
• Self contained executable
packaged in Scratch image
Hello World
Copyright © 2022, Oracle and/or its affiliates
9
Base OS Image
JDK Modules
shared libs
JVM JDK Tools
Application Code
musl libc
Required libs
Let’s go back to the start!
Copyright © 2022, Oracle and/or its affiliates
10 Photo by 愚木混株 cdd20 on Unsplash
Copyright © 2022, Oracle and/or its affiliates
11
https://blogs.oracle.com/javamagazine/post/java-18-simple-web-server
Copyright © 2022, Oracle and/or its affiliates
12
https://blogs.oracle.com/javamagazine/post/java-18-simple-web-server
JDK on Debian 11 Slim Linux
Copyright © 2022, Oracle and/or its affiliates
13
Debian 11-Slim
JDK Modules
JVM
shared libs
JDK Tools
JDK 17 303 MB
Debian 11 slim + 80 MB
---------
383 MB
"Distroless" images contain only your
application and its runtime dependencies.
They do not contain package managers,
shells or any other programs you would
expect to find in a standard Linux
distribution.
https://github.com/GoogleContainerTools/distroless/blob/main/README.md
Copyright © 2022, Oracle and/or its affiliates
14
JDK on Distroless “Java 17”
Copyright © 2022, Oracle and/or its affiliates
15
Debian
JDK Modules
JVM libs
JVM JDK Tools
Distroless JDK 17 231 MB
jlink on Distroless “Java Base”
Copyright © 2022, Oracle and/or its affiliates
16
Debian
JDK Modules
JVM libs
JVM
Custom JRE 35.0 MB
Distroless Java
Base
+ 39.4 MB
---------
74.9 MB
Dynamically linked executable
GraalVM Native Image with Distroless “Java Base”
Copyright © 2022, Oracle and/or its affiliates
17
SVM
Needed JDK
Classes
Debian
JVM libs
Native Executable 19.0 MB
Distroless Java
Base
+ 39.4 MB
---------
~58.7 MB
GraalVM Native Executable Linking and Containerization Options
Copyright © 2022, Oracle and/or its affiliates
18
glibc
stdlibc++, zlib, etc.
Application Code
Fully Dynamic
OS must include all
dynamically linked libs
Application Code
Application Code
glibc
stdlibc++, zlib,
etc.
Mostly Static
musl libc
stdlibc++, zlib,
etc.
Fully Static
OS only need provide
libc.
No libs provided by OS
Mostly statically linked executable
GraalVM Native Image with Distroless “Base”
Copyright © 2022, Oracle and/or its affiliates
19
glibc
Required Libs
Needed JDK
Classes
SVM
Debian
Native Executable 19.0 MB
Distroless Base + 20.3 MB
---------
~39.7 MB
Alpine Linux is a security-oriented,
lightweight Linux distribution based on
musl libc and busybox.
Copyright © 2022, Oracle and/or its affiliates
20
Statically linked executable
GraalVM Native Image with Alpine Linux
Copyright © 2022, Oracle and/or its affiliates
21
Required Libs
Needed JDK
Classes
SVM
Native Executable 19.00 MB
Alpine + 5.54 MB
---------
~25 MB
Debian
Statically linked executable
GraalVM Native Image with Distroless “Static”
Copyright © 2022, Oracle and/or its affiliates
22
Required Libs
Needed JDK
Classes
SVM
Native Executable 19.00 MB
Distroless Static + ~2.36 MB
---------
~21.8 MB
This image is most useful in the context of
building base...or super minimal images
(that contain only a single binary and
whatever it requires...)”
Copyright © 2022, Oracle and/or its affiliates
23
scratch
Statically linked executable
GraalVM Native Image on Scratch
Copyright © 2022, Oracle and/or its affiliates
24
Required Libs
Needed JDK
Classes
SVM
Native Executable 19.00 MB
Scratch + ~0 MB
---------
~19.4 MB
UPX
A free, secure, portable, extendable, high-performance executable packer for several
executable formats
UPX: the Ultimate Packer for eXecutables
Copyright © 2022, Oracle and/or its affiliates
25
Executable Executable
UPX
A free, secure, portable, extendable, high-performance executable packer for several
executable formats
UPX: the Ultimate Packer for eXecutables
Copyright © 2022, Oracle and/or its affiliates
26
Executable Executable
19 MB
5.45 MB
Statically linked executable compressed with UPX
GraalVM Native Image on Scratch
Copyright © 2022, Oracle and/or its affiliates
27
Required Libs
Needed JDK
Classes
SVM
Native Executable
(Compressed)
5.45 MB
Scratch + ~0 MB
---------
~5.45 MB
Copyright © 2022, Oracle and/or its affiliates
28
0
50
100
150
200
250
300
350
400
Debian Slim / JDK
17
Distrolesss Java
17
Distroless Java
Base / jlink
Distroless Java
Base / Dynamic
Executable
Distroless Base /
Mostly Static
Executable
Alpine / Static
Executable
Distroless Static /
Static Executable
Scartch / Static
Executable
Scratch /
Compressed Static
Executable
383
231
74.9
58.7
39.7
25 21.8 19.4
5.45
Container Image Sizes (MB)
JVM
GraalVM Native Image
GraalVM Native Image—Ideal for Cloud Native Applications
Copyright © 2022, Oracle and/or its affiliates
29
Low Resource
Usage
Start Fast
Small
Container
Image
Minimize
Vulnerability
www.graalvm.org oracle.com/graalvm
More GraalVM @ Devoxx
Copyright © 2022, Oracle and/or its affiliates
30
Learn More @ graalvm.org
Shaun Smith
Senior Director
Oracle Labs—GraalVM
@shaunMsmith
Copyright © 2022, Oracle and/or its affiliates
32

More Related Content

PPTX
Practical Tips for Hardening Java Applications
PDF
Commit to excellence - Java in containers
PPTX
Bring the Action: Using GraalVM in Production
PDF
MySQL Database Architectures - 2022-08
PDF
JVMs in Containers
PDF
Unikernels - Bristech June 2016
PDF
JVMs in Containers - Best Practices
PDF
Package your Java EE Application using Docker and Kubernetes
Practical Tips for Hardening Java Applications
Commit to excellence - Java in containers
Bring the Action: Using GraalVM in Production
MySQL Database Architectures - 2022-08
JVMs in Containers
Unikernels - Bristech June 2016
JVMs in Containers - Best Practices
Package your Java EE Application using Docker and Kubernetes

Similar to A 1.5MB Java Container App? Yes you can! (20)

PDF
Dockerizing Oracle Database
PDF
Java 40 versions_sgp
PPTX
Getting started with Docker sandboxes for MariaDB
PDF
6212883126866262792 performance testing_cloud
PDF
MySQL Innovation Day Chicago - MySQL HA So Easy : That's insane !!
PDF
MySQL docker with demo by Ramana Yeruva
PDF
Jaoo Michael Neale 09
PDF
Java Cloud and Container Ready
PDF
MySQL Shell for DBAs
PDF
CloudTalks - Revolutionize Java DB AppDev with Reactive Streams and Virtual T...
PDF
Java in a world of containers
PDF
Java in a World of Containers - DockerCon 2018
PDF
MySQL Database Architectures - 2020-10
PDF
Cloud Conference Day - Revolutionize Java Database App Development with React...
PDF
Another MySQL HA Solution for ProxySQL Users, Easy and All Integrated: MySQL ...
PDF
FOSDEM 2022 MySQL Devroom: MySQL 8.0 - Logical Backups, Snapshots and Point-...
PDF
State of The Dolphin - May 2021
PDF
Percona Live 2022 - The Evolution of a MySQL Database System
PDF
Percona Live 2022 - MySQL Architectures
PDF
DevOps Supercharged with Docker on Exadata
Dockerizing Oracle Database
Java 40 versions_sgp
Getting started with Docker sandboxes for MariaDB
6212883126866262792 performance testing_cloud
MySQL Innovation Day Chicago - MySQL HA So Easy : That's insane !!
MySQL docker with demo by Ramana Yeruva
Jaoo Michael Neale 09
Java Cloud and Container Ready
MySQL Shell for DBAs
CloudTalks - Revolutionize Java DB AppDev with Reactive Streams and Virtual T...
Java in a world of containers
Java in a World of Containers - DockerCon 2018
MySQL Database Architectures - 2020-10
Cloud Conference Day - Revolutionize Java Database App Development with React...
Another MySQL HA Solution for ProxySQL Users, Easy and All Integrated: MySQL ...
FOSDEM 2022 MySQL Devroom: MySQL 8.0 - Logical Backups, Snapshots and Point-...
State of The Dolphin - May 2021
Percona Live 2022 - The Evolution of a MySQL Database System
Percona Live 2022 - MySQL Architectures
DevOps Supercharged with Docker on Exadata
Ad

More from Shaun Smith (14)

PDF
Serverless Java: JJUG CCC 2019
PPTX
Functions and DevOps
PPTX
Democratizing Serverless
PDF
Polyglot! A Lightweight Cloud Platform for Java SE, Node, and More
PDF
Lightweight Java in the Cloud
PDF
EclipseLink: Beyond Relational and NoSQL to Polyglot and HTML5
PPT
Practical RESTful Persistence
PPTX
The Evolution of Java Persistence
ODP
EclipseCon 2011-Gemini Naming
ODP
EclipseCon 2011-Gemini Intro
ODP
EclipseCon 2011-Gemini JPA
PPT
RESTful Data Access Services with Java EE
PPT
RESTful services with JAXB and JPA
PPT
OSGi Persistence With EclipseLink
Serverless Java: JJUG CCC 2019
Functions and DevOps
Democratizing Serverless
Polyglot! A Lightweight Cloud Platform for Java SE, Node, and More
Lightweight Java in the Cloud
EclipseLink: Beyond Relational and NoSQL to Polyglot and HTML5
Practical RESTful Persistence
The Evolution of Java Persistence
EclipseCon 2011-Gemini Naming
EclipseCon 2011-Gemini Intro
EclipseCon 2011-Gemini JPA
RESTful Data Access Services with Java EE
RESTful services with JAXB and JPA
OSGi Persistence With EclipseLink
Ad

Recently uploaded (20)

PPTX
CHAPTER 2 - PM Management and IT Context
PDF
medical staffing services at VALiNTRY
PPTX
ai tools demonstartion for schools and inter college
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Transform Your Business with a Software ERP System
PPTX
assetexplorer- product-overview - presentation
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
System and Network Administraation Chapter 3
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Reimagine Home Health with the Power of Agentic AI​
PPTX
Introduction to Artificial Intelligence
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
top salesforce developer skills in 2025.pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
CHAPTER 2 - PM Management and IT Context
medical staffing services at VALiNTRY
ai tools demonstartion for schools and inter college
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Transform Your Business with a Software ERP System
assetexplorer- product-overview - presentation
Designing Intelligence for the Shop Floor.pdf
PTS Company Brochure 2025 (1).pdf.......
wealthsignaloriginal-com-DS-text-... (1).pdf
Operating system designcfffgfgggggggvggggggggg
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
System and Network Administraation Chapter 3
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
How to Choose the Right IT Partner for Your Business in Malaysia
Wondershare Filmora 15 Crack With Activation Key [2025
Reimagine Home Health with the Power of Agentic AI​
Introduction to Artificial Intelligence
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
top salesforce developer skills in 2025.pdf
Design an Analysis of Algorithms II-SECS-1021-03

A 1.5MB Java Container App? Yes you can!

  • 1. A 1.5MB Java Container App? Yes you can! Shaun Smith Senior Director Oracle Labs—GraalVM @shaunMsmith
  • 2. Copyright © 2022, Oracle and/or its affiliates 2
  • 3. Let’s start at the end! Copyright © 2022, Oracle and/or its affiliates 3 Photo by 愚木混株 cdd20 on Unsplash
  • 4. Hello World Copyright © 2022, Oracle and/or its affiliates 4
  • 5. GraalVM Enterprise Native Image—Ahead-of-time compiler & runtime Copyright © 2022, Oracle and/or its affiliates 5 Windows Executable MacOS Executable Linux Executable .class .jar .class .jar
  • 6. Copyright © 2022, Oracle and/or its affiliates 6
  • 7. Copyright © 2022, Oracle and/or its affiliates 7 Demo 1.5 MB Hello World Container
  • 8. Copyright © 2022, Oracle and/or its affiliates 8 231 1.5 0 50 100 150 200 250 JDK / Distroless Java GraalVM Native Image / Scratch JVM vs GraalVM Native Image (MB)
  • 9. 231 MB Container • Minimal JDK with JVM required libs using Distroless Java 17 1.5 MB Container • Only needed code • Only needed JDK • Required libs statically linked • Self contained executable packaged in Scratch image Hello World Copyright © 2022, Oracle and/or its affiliates 9 Base OS Image JDK Modules shared libs JVM JDK Tools Application Code musl libc Required libs
  • 10. Let’s go back to the start! Copyright © 2022, Oracle and/or its affiliates 10 Photo by 愚木混株 cdd20 on Unsplash
  • 11. Copyright © 2022, Oracle and/or its affiliates 11 https://blogs.oracle.com/javamagazine/post/java-18-simple-web-server
  • 12. Copyright © 2022, Oracle and/or its affiliates 12 https://blogs.oracle.com/javamagazine/post/java-18-simple-web-server
  • 13. JDK on Debian 11 Slim Linux Copyright © 2022, Oracle and/or its affiliates 13 Debian 11-Slim JDK Modules JVM shared libs JDK Tools JDK 17 303 MB Debian 11 slim + 80 MB --------- 383 MB
  • 14. "Distroless" images contain only your application and its runtime dependencies. They do not contain package managers, shells or any other programs you would expect to find in a standard Linux distribution. https://github.com/GoogleContainerTools/distroless/blob/main/README.md Copyright © 2022, Oracle and/or its affiliates 14
  • 15. JDK on Distroless “Java 17” Copyright © 2022, Oracle and/or its affiliates 15 Debian JDK Modules JVM libs JVM JDK Tools Distroless JDK 17 231 MB
  • 16. jlink on Distroless “Java Base” Copyright © 2022, Oracle and/or its affiliates 16 Debian JDK Modules JVM libs JVM Custom JRE 35.0 MB Distroless Java Base + 39.4 MB --------- 74.9 MB
  • 17. Dynamically linked executable GraalVM Native Image with Distroless “Java Base” Copyright © 2022, Oracle and/or its affiliates 17 SVM Needed JDK Classes Debian JVM libs Native Executable 19.0 MB Distroless Java Base + 39.4 MB --------- ~58.7 MB
  • 18. GraalVM Native Executable Linking and Containerization Options Copyright © 2022, Oracle and/or its affiliates 18 glibc stdlibc++, zlib, etc. Application Code Fully Dynamic OS must include all dynamically linked libs Application Code Application Code glibc stdlibc++, zlib, etc. Mostly Static musl libc stdlibc++, zlib, etc. Fully Static OS only need provide libc. No libs provided by OS
  • 19. Mostly statically linked executable GraalVM Native Image with Distroless “Base” Copyright © 2022, Oracle and/or its affiliates 19 glibc Required Libs Needed JDK Classes SVM Debian Native Executable 19.0 MB Distroless Base + 20.3 MB --------- ~39.7 MB
  • 20. Alpine Linux is a security-oriented, lightweight Linux distribution based on musl libc and busybox. Copyright © 2022, Oracle and/or its affiliates 20
  • 21. Statically linked executable GraalVM Native Image with Alpine Linux Copyright © 2022, Oracle and/or its affiliates 21 Required Libs Needed JDK Classes SVM Native Executable 19.00 MB Alpine + 5.54 MB --------- ~25 MB
  • 22. Debian Statically linked executable GraalVM Native Image with Distroless “Static” Copyright © 2022, Oracle and/or its affiliates 22 Required Libs Needed JDK Classes SVM Native Executable 19.00 MB Distroless Static + ~2.36 MB --------- ~21.8 MB
  • 23. This image is most useful in the context of building base...or super minimal images (that contain only a single binary and whatever it requires...)” Copyright © 2022, Oracle and/or its affiliates 23 scratch
  • 24. Statically linked executable GraalVM Native Image on Scratch Copyright © 2022, Oracle and/or its affiliates 24 Required Libs Needed JDK Classes SVM Native Executable 19.00 MB Scratch + ~0 MB --------- ~19.4 MB
  • 25. UPX A free, secure, portable, extendable, high-performance executable packer for several executable formats UPX: the Ultimate Packer for eXecutables Copyright © 2022, Oracle and/or its affiliates 25 Executable Executable
  • 26. UPX A free, secure, portable, extendable, high-performance executable packer for several executable formats UPX: the Ultimate Packer for eXecutables Copyright © 2022, Oracle and/or its affiliates 26 Executable Executable 19 MB 5.45 MB
  • 27. Statically linked executable compressed with UPX GraalVM Native Image on Scratch Copyright © 2022, Oracle and/or its affiliates 27 Required Libs Needed JDK Classes SVM Native Executable (Compressed) 5.45 MB Scratch + ~0 MB --------- ~5.45 MB
  • 28. Copyright © 2022, Oracle and/or its affiliates 28 0 50 100 150 200 250 300 350 400 Debian Slim / JDK 17 Distrolesss Java 17 Distroless Java Base / jlink Distroless Java Base / Dynamic Executable Distroless Base / Mostly Static Executable Alpine / Static Executable Distroless Static / Static Executable Scartch / Static Executable Scratch / Compressed Static Executable 383 231 74.9 58.7 39.7 25 21.8 19.4 5.45 Container Image Sizes (MB) JVM GraalVM Native Image
  • 29. GraalVM Native Image—Ideal for Cloud Native Applications Copyright © 2022, Oracle and/or its affiliates 29 Low Resource Usage Start Fast Small Container Image Minimize Vulnerability www.graalvm.org oracle.com/graalvm
  • 30. More GraalVM @ Devoxx Copyright © 2022, Oracle and/or its affiliates 30
  • 31. Learn More @ graalvm.org Shaun Smith Senior Director Oracle Labs—GraalVM @shaunMsmith
  • 32. Copyright © 2022, Oracle and/or its affiliates 32

Editor's Notes

  • #2: Containers are increasing the way Java applications are packaged and deployed. There are lots of qualities desirable in a containerized application like fast startup and low memory and CPU requirements, but size and security are also important considerations. Moving big container images around a network will increase the time it takes to start up a new K8s pod or launch a container, and "just enough operating system" container images with reduced attack surface area are also preferable. So what’s the smallest possible Java container image? In this session we’ll demonstrate how to build containerized Java applications small as a mere 1.5MB! Using GraalVM Native Image ahead-of-time compilation and static linking with musl libc we can shrink down and strip out all the unnecessary bits that bloat a typical Java apps and deploy them in lightweight and security focused container images like Alpine and distroless–even scratch!
  • #32: Containers are increasing the way Java applications are packaged and deployed. There are lots of qualities desirable in a containerized application like fast startup and low memory and CPU requirements, but size and security are also important considerations. Moving big container images around a network will increase the time it takes to start up a new K8s pod or launch a container, and "just enough operating system" container images with reduced attack surface area are also preferable. So what’s the smallest possible Java container image? In this session we’ll demonstrate how to build containerized Java applications small as a mere 1.5MB! Using GraalVM Native Image ahead-of-time compilation and static linking with musl libc we can shrink down and strip out all the unnecessary bits that bloat a typical Java apps and deploy them in lightweight and security focused container images like Alpine and distroless–even scratch!