201

Java 11 is announced to be the most recent LTS version. So, we're trying to start new services based on this Java version.

However, the base Docker image for Java 11 is much larger than the equivalent for Java 8:

(I'm considering only the official OpenJDK and the most lightweight images for each Java version.)

Deeper digging uncovered the following "things":

  • the openjdk:11-jre-slim image uses the base image debian:sid-slim. This brings 2 issues:

    • this is 60 MB larger than alpine:3.8

    • the Debian sid versions are unstable

  • the openjdk-11-jre-headless package installed in the image is 3 times larger than openjdk8-jre (inside running Docker container):

    • openjdk:8-jre-alpine:

      / # du -hs /usr/lib/jvm/java-1.8-openjdk/jre/lib/
      57.5M   /usr/lib/jvm/java-1.8-openjdk/jre/lib/
      
    • openjdk:11-jre-slim:

      # du -sh /usr/lib/jvm/java-11-openjdk-amd64/lib/
      179M    /usr/lib/jvm/java-11-openjdk-amd64/lib/
      

      Going deeper I discovered the "root" of this heaviness - it's the modules file of the JDK:

      # ls -lhG /usr/lib/jvm/java-11-openjdk-amd64/lib/modules
      135M    /usr/lib/jvm/java-11-openjdk-amd64/lib/modules
      

So, now the questions which came:

  • Why is alpine not used any more as a base image for Java 11 slim images?

  • Why is the unstable sid version used for LTS Java images?

  • Why is the slim/headless/JRE package for OpenJDK 11 so large compared to the similar OpenJDK 8 package?

    • What is this modules file which brings 135 MB in OpenJDK 11?

UPD: as a solutions for these challenges one could use this answer: Java 11 application as docker image

radistao
  • 14,889
  • 11
  • 66
  • 92
  • 1
    Well for one new versions (JDK 9+) of Java are [modularized](https://www.oracle.com/corporate/features/understanding-java-9-modules.html), which explains why there are modules in 11 vs 8. – Zachary Craig Nov 19 '18 at 14:02
  • 1
    Related read possibly - [Benchmarking Debian vs Alpine as a Base Docker Image](https://nickjanetakis.com/blog/benchmarking-debian-vs-alpine-as-a-base-docker-image) – Naman Nov 19 '18 at 15:05
  • 14
    There is no JRE 11, so what you have, is a full JDK. You can create compact environments, even slimmer than JRE 8, but it requires an actual modular application, so that the dependencies are known. – Holger Nov 19 '18 at 15:24
  • 1
    Additionally to the above, not all those *modules* that you find as the reason of increase in size are actually required for your applications. But to find out which ones you shall proceed towards creating a modular application. You can find out more about [tag:jlink] (introduced in Java9) for that sake. – Naman Nov 19 '18 at 15:37
  • 1
    What could be a better time to get to read this online - https://twitter.com/LogicTheoryIO/status/1064503559071371265 – Naman Nov 19 '18 at 16:39
  • @Holger > There is no JRE 11, so what you have, is a full JDK. Hm. This makes even more confusing, because there are both `11-jre-slim` and `11-jdk-slim`, but what is even more confusing: "src.zip" in that jdk image is a broken soft link (so, "src.zip" is not there!) – radistao Nov 20 '18 at 08:36
  • Dockerhub says 69mb. Or isn't that the final size? -> https://hub.docker.com/layers/openjdk/library/openjdk/11-jre-slim/images/sha256-145ffab4f761cb527609ebe3e5ceed61b298d33022b5bb5e432918fe9bfebf9d – GabrielBB Jan 20 '20 at 00:32
  • the downloaded (pulled) image size is still 204 Mb (at least for current `openjdk:11-jre-slim` image). Not sure what size is published on Dockerhub. Maybe it's a size of the layer with JRE only. – radistao Jan 20 '20 at 11:28
  • AdoptOpenJDK has an alpine image for JRE 11 here: https://hub.docker.com/r/adoptopenjdk/openjdk11 . It's not an official image but maintained by AdoptOpenJDK – aldok Sep 27 '20 at 16:21

4 Answers4

206

Why is alpine not used any more as a base image for Java 11 slim images?

That's because, sadly, there is no official stable OpenJDK 11 build for Alpine currently.

Alpine uses musl libc, as opposed to the standard glibc used by most Linuxes out there, which means that a JVM must be compatible with musl libc for supporting vanilla Alpine. The musl OpenJDK port is being developed under OpenJDK's Portola project.

The current status is summarized on the OpenJDK 11 page:

The Alpine Linux build previously available on this page was removed as of JDK 11 GA. It’s not production-ready because it hasn’t been tested thoroughly enough to be considered a GA build. Please use the early-access JDK 12 Alpine Linux build in its place.

The only stable OpenJDK versions for Alpine currently are 7 and 8, provided by the IcedTea project.

However - if you're willing to consider other than the official OpenJDK, Azul's Zulu OpenJDK offers a compelling alternative:

  • It supports Java 11 on Alpine musl (version 11.0.2 as of the time of writing);
  • It is a certified OpenJDK build, verified using the OpenJDK TCK compliance suite;
  • It is free, open source and docker ready (Dockerhub).

For support availability and roadmap, see Azul support roadmap.

Update, 3/6/19: As of yesterday, openjdk11 is available in Alpine repositories! It could be grabbed on Alpine using:

apk --no-cache add openjdk11

The package is based on the jdk11u OpenJDK branch plus ported fixes from project Portola, introduced with the following PR. Kudos and huge thanks to the Alpine team.

Why is the unstable sid version used for LTS Java images?

That's a fair question / request. There's actually an open ticket for providing Java 11 on a stable Debian release:
https://github.com/docker-library/openjdk/issues/237

Update, 26/12/18: The issue has been resolved, and now the OpenJDK 11 slim image is based on stretch-backports OpenJDK 11 which was recently made available (PR link).

Why is the slim/headless/JRE package for OpenJDK 11 so large compared to the similar OpenJDK 8 package? What is this modules file which brings 135 MB in OpenJDK 11?

Java 9 introduced the module system, which is a new and improved approach for grouping packages and resources, compared to jar files. This article from Oracle gives a very detailed introduction to this feature:
https://www.oracle.com/corporate/features/understanding-java-9-modules.html

The modules file bundles all modules shipped with the JRE. The complete list of modules could be printed with java --list-modules. modules is indeed a very large file, and as commented, it contains all standard modules, and it is therefore quite bloated.

One thing to note however is that it replaces rt.jar and tools.jar which became deprecated, among other things, so when accounting for the size of modules when comparing to pre-9 OpenJDK builds, the sizes of rt.jar and tools.jar should be subtracted (they should take up some 80MB combined).

valiano
  • 16,433
  • 7
  • 64
  • 79
18

If you are considering only Official Images and your target achievement is to use the smaller JRE image available, I would suggest you to look at the official OpenJDK image openjdk:11-jre-slim-buster which is just 69.2 MB.

Davide Martorana
  • 691
  • 3
  • 8
  • 20
  • https://hub.docker.com/layers/openjdk/library/openjdk/11.0.9-jre-slim-buster/ – Alex Punnen Nov 10 '20 at 11:21
  • image size of openjdk:11-jre-slim-buster is 129.7MB !!! – Zhasulan Berdibekov Aug 25 '21 at 09:41
  • 1
    @ЖасуланБердибеков I was referring to the compressed size, which is a good indicator to compare images sizes at runtime. Please see: https://hub.docker.com/layers/openjdk/library/openjdk/11.0.11-jre-slim-buster/images/sha256-1efc10742a26c56416e400611b1d7ba871dab6c478e8017ab0a226d87f26b78b?context=explore – Davide Martorana Aug 26 '21 at 10:50
13

as for 07.2019 https://adoptopenjdk.net/ has official Alpine support for Java 11:

However, modules (jmods, jlink) still shall be considered when one assembles minimal application.

Note: slim images don't contain some modules (like java.sql) - they are excluded explicitly (https://github.com/AdoptOpenJDK/openjdk-docker/blob/21b8393b9c23f94d6921a56cce27b026537c6ca2/11/jdk/alpine/slim-java.sh#L233)

radistao
  • 14,889
  • 11
  • 66
  • 92
  • Thanks to your useful answer i got to understand what's excluded in the slim images. But one question i have is why does it exclude the `java.se` module aswell, isn't that needed?? – lmk Aug 24 '21 at 23:58
  • The Eclipse Temurin images may be also interesting: https://hub.docker.com/_/eclipse-temurin – aemaem Jul 08 '22 at 07:13
2

https://hub.docker.com/_/openjdk?tab=tags&page=1&name=11.0.7-jre-slim

in docker openjdk repository, slim jre 11 image is less than 70mb

Javier Aviles
  • 7,952
  • 2
  • 22
  • 28
  • 1
    out of curiousity, do you know the difference between the two images there? 11.0.7-jre-slim-buster and 11.0.7-jre-slim – hafiz ali Jul 08 '21 at 13:15
  • 1
    buster, jessie or stretch are the suite code names for releases of Debian and indicate which release the image is based on. – Javier Aviles Jul 15 '21 at 09:44