Create a minimal JRE around a Maven project and ship it as lightweight Docker image
-
/server folder contains a lazy Hello-World webserver based on Javalin. The code is packaged as single Jar using the maven-assembly-plugin
- run.sh is the entrypoint for the dockerized application
-
Dockerfile describes 4 images based on the blazing fast GraalVM CE JDK artifact:
-
base_image: Ubuntu 22.04 docker image + GraalVM CE JDK
-
server_builder: builds the maven project and creates the minimal JRE. Base modules are discovered using jdeps and exported as JRE distribution by jlink
-
minimal_jre_image: ships the minimal JRE for the server application
-
jdk_image: contains the whole GraalVM JDK
-
Image | Size | vs JDK | vs JRE |
---|---|---|---|
JDK | 835MB | - | 618% |
JRE | 135MB | 16% | - |
The jre based image is 84% smaller than the optimized-jre one
Image | Time | vs JDK | vs JRE |
---|---|---|---|
JDK | 502ms | - | 127% |
JRE | 395ms | 78% | - |
The jre based image is 22% faster to start-up than the optimized-jre one