![]() The solutionĪlong with modularity Java 9 has introduced a new tool called jlink. Pretty huge image for a 7MB jar file, right? Here’s what we can do about it. Jvm-in-docker jdk 4126e7e5ce37 51 minutes ago 341MB In my case this is how the output looks like: ĭocker image ls | grep -e "jvm-in-docker.*jdk" Let’s build the image and check it’s size: docker build -t jvm-in-docker:jre -f jre.dockerfile. It uses an Amazon corretto JDK image as a base, creates a non-root user to run the app, and then copies the jar file into the image. RUN adduser -no-create-home -u 1000 -D $APPLICATION_USERĬOPY -chown=1000:1000. Here’s how the Dockerfile would look like for a typical JDK-based image: FROM amazoncorretto:17.0.3-alpine It has a small app there that runs a web server on port 8080 and replies with “Hello, world!” to a GET request. JDK comes with tools, sources and documentation that you don’t need to run your app. Unfortunately if you’re using such images as is, then you’re wasting the space of your Docker image registry, your local machine and network bandwidth downloading and uploading them. That’s the philosophy that many docker image maintainers have adopted, omitting exclusive JRE images and only shipping images with JDK. There’s no need to try to distribute one JRE that will fit all, instead everyone can create a JRE image suitable for their own needs. The reason for that is the modularity introduced in Java 9. For example, if our app doesn’t use network stack anyhow or doesn’t interact with the desktop environment, we can omit and sktop packages from the image, saving a few megabytes of space.Īnd starting with Java 11, JRE doesn’t have its own separate distribution, there’s no way to install it without installing JDK. It lets us create our very own JRE image optimized for our needs. With Java 9 there was introduced Platform Module Subsystem (JPMS). Let’s see how to reduce Java docker image size dramatically. At Wolt we strive to be efficient and sustainable, so such a waste of space shall not be tolerated. In my case using such an image was resulting in an app image of 414MB, where the app itself was only taking around 60MB. As a result of this change, many official Docker images don’t offer a JRE-only image, e.g.: official openjdk images, Amazon corretto images. If you’ve been using Kotlin or Scala (like we are at Wolt) or any other JVM based language for a while, you might have noticed that starting with Java 11, Java Runtime Environment (JRE) doesn’t have a separate distribution anymore, it is only distributed as a part of Java Development Kit (JDK). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |