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:
the openjdk-11-jre-headless
package installed in the image is 3 times larger than openjdk8-jre
(inside running Docker container):
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
Why is alpine
not used any more as a base image for Java 11 slim images?
That's because, sadly, currently there is no official stable OpenJDK 11 build for Alpine.
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.
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).
On the downside, LTS support is only available for the enterprise edition and not guarenteed for the community builds (see roadmap).
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).