简体   繁体   English

为什么 Java 11 基础 Docker 镜像如此之大? (openjdk:11-jre-slim)

[英]Why is the Java 11 base Docker image so large? (openjdk:11-jre-slim)

Java 11 is announced to be the most recent LTS version. Java 11 被宣布为最新的 LTS 版本。 So, we're trying to start new services based on this Java version.因此,我们正在尝试基于此 Java 版本启动新服务。

However, the base Docker image for Java 11 is much larger than the equivalent for Java 8:但是,Java 11 的基础 Docker 镜像比 Java 8 的等价镜像大得多:

(I'm considering only the official OpenJDK and the most lightweight images for each Java version.) (我只考虑官方 OpenJDK和每个 Java 版本最轻量级的图像。)

Deeper digging uncovered the following "things":深入挖掘发现了以下“事情”:

  • the openjdk:11-jre-slim image uses the base image debian:sid-slim . openjdk:11-jre-slim镜像使用基础镜像debian:sid-slim This brings 2 issues:这带来了2个问题:

    • this is 60 MB larger than alpine:3.8这比alpine:3.8大 60 MB alpine:3.8

    • the Debian sid versions are unstable Debian sid版本不稳定

  • the openjdk-11-jre-headless package installed in the image is 3 times larger than openjdk8-jre (inside running Docker container):镜像中安装的openjdk-11-jre-headless包比openjdk8-jre大 3 倍(在运行的 Docker 容器中):

    • openjdk:8-jre-alpine : 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 : 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:更深入地我发现了这种沉重的“根源”——它是 JDK 的modules文件:

       # 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?为什么alpine不再用作 Java 11 slim 映像的基本映像?

  • Why is the unstable sid version used for LTS Java images?为什么 LTS Java 镜像使用的是不稳定的sid版本?

  • Why is the slim/headless/JRE package for OpenJDK 11 so large compared to the similar OpenJDK 8 package?为什么 OpenJDK 11 的 slim/headless/JRE 包与类似的 OpenJDK 8 包相比如此之大?

    • What is this modules file which brings 135 MB in OpenJDK 11?在 OpenJDK 11 中带来 135 MB 的模块文件是什么?

UPD : as a solutions for these challenges one could use this answer: Java 11 application as docker image UPD :作为这些挑战的解决方案,可以使用以下答案: Java 11 application as docker image

Why is alpine not used any more as a base image for Java 11 slim images?为什么alpine不再用作 Java 11 slim 映像的基本映像?

That's because, sadly, there is no official stable OpenJDK 11 build for Alpine currently.遗憾的是,这是因为目前没有针对 Alpine 的官方稳定版 OpenJDK 11 版本。

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. Alpine 使用 musl libc,而不是大多数 Linux 使用的标准 glibc,这意味着 JVM 必须与 musl libc 兼容才能支持 vanilla Alpine。 The musl OpenJDK port is being developed under OpenJDK's Portola project. musl OpenJDK 端口正在 OpenJDK 的Portola项目下开发。

The current status is summarized on the OpenJDK 11 page :当前状态总结在OpenJDK 11 页面上

The Alpine Linux build previously available on this page was removed as of JDK 11 GA.从 JDK 11 GA 开始,此页面上先前提供的 Alpine Linux 版本已被删除。 It's not production-ready because it hasn't been tested thoroughly enough to be considered a GA build.它不是生产就绪的,因为它没有经过足够彻底的测试,无法被视为 GA 版本。 Please use the early-access JDK 12 Alpine Linux build in its place.请使用早期访问的 JDK 12 Alpine Linux 版本来代替它。

The only stable OpenJDK versions for Alpine currently are 7 and 8, provided by the IcedTea project.目前,Alpine 唯一稳定的 OpenJDK 版本是 7 和 8,由IcedTea项目提供。

However - if you're willing to consider other than the official OpenJDK, Azul's Zulu OpenJDK offers a compelling alternative:但是 - 如果您愿意考虑官方 OpenJDK 以外的其他产品, Azul 的 Zulu OpenJDK 提供了一个引人注目的替代方案:

  • It supports Java 11 on Alpine musl (version 11.0.2 as of the time of writing);在 Alpine musl 上支持Java 11 (截至撰写本文时为 11.0.2 版);
  • It is a certified OpenJDK build, verified using the OpenJDK TCK compliance suite;它是经过认证的 OpenJDK 构建,使用 OpenJDK TCK 合规套件进行验证;
  • It is free, open source and docker ready ( Dockerhub ).它是免费的、开源的并且支持docker ( Dockerhub )。

For support availability and roadmap, see Azul support roadmap .有关支持可用性和路线图,请参阅Azul 支持路线图

Update, 3/6/19: As of yesterday, openjdk11 is available in Alpine repositories! 2019 年 3 月 6 日更新:截至昨天, openjdk11在 Alpine 存储库中可用! It could be grabbed on Alpine using:可以使用以下方法在 Alpine 上抓取它:

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 .该包基于jdk11u OpenJDK 分支以及来自项目 Portola 的移植修复,引入以下PR Kudos and huge thanks to the Alpine team.非常感谢 Alpine 团队。

Why is the unstable sid version used for LTS Java images?为什么 LTS Java 镜像使用的是不稳定的sid版本?

That's a fair question / request.这是一个公平的问题/要求。 There's actually an open ticket for providing Java 11 on a stable Debian release:实际上有一个在稳定的 Debian 版本上提供 Java 11 的公开票:
https://github.com/docker-library/openjdk/issues/237 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 ). 2018 年 12 月 26 日更新:问题已解决,现在 OpenJDK 11 超薄映像基于最近推出的stretch-backports OpenJDK 11( PR 链接)。

Why is the slim/headless/JRE package for OpenJDK 11 so large compared to the similar OpenJDK 8 package?为什么 OpenJDK 11 的 slim/headless/JRE 包与类似的 OpenJDK 8 包相比如此之大? What is this modules file which brings 135 MB in OpenJDK 11?在 OpenJDK 11 中带来 135 MB 的模块文件是什么?

Java 9 introduced the module system, which is a new and improved approach for grouping packages and resources, compared to jar files. Java 9 引入了模块系统,与 jar 文件相比,这是一种新的改进方法,用于对包和资源进行分组。 This article from Oracle gives a very detailed introduction to this feature: Oracle的这篇文章非常详细的介绍了这个特性:
https://www.oracle.com/corporate/features/understanding-java-9-modules.html https://www.oracle.com/corporate/features/understanding-java-9-modules.html

The modules file bundles all modules shipped with the JRE. modules文件捆绑了 JRE 附带的所有模块。 The complete list of modules could be printed with java --list-modules .完整的模块列表可以用java --list-modules打印。 modules is indeed a very large file, and as commented, it contains all standard modules, and it is therefore quite bloated. modules确实是一个非常大的文件,正如评论中所说,它包含所有标准模块,因此它非常臃肿。

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).然而,需要注意的一件事是它取代了rt.jartools.jar ,其中不推荐使用,因此在考虑modules的大小时,与 9 之前的 OpenJDK 版本相比, rt.jartools.jar的大小tools.jar应该被减去(它们应该占用大约 80MB 的总和)。

as for 07.2019 https://adoptopenjdk.net/ has official Alpine support for Java 11:至于 07.2019 https://adoptopenjdk.net/对 Java 11 有正式的 Alpine 支持:

However, modules ( jmods , jlink ) still shall be considered when one assembles minimal application.然而,模块(jmods, jlink )仍然应被视为当一个组装最小应用程序。

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 )注意图像不包含某些模块(如java.sql )-它们被明确排除( https://github.com/AdoptOpenJDK/openjdk-docker/blob/21b8393b9c23f94d6921a56cce27b026537c6ca2/11/jdk/alpine/slim-java. sh#L233 )

如果您只考虑官方镜像并且您的目标是使用可用的较小 JRE 镜像,我建议您查看官方 OpenJDK镜像openjdk:11-jre-slim-buster ,它只有 69.2 MB。

https://hub.docker.com/_/openjdk?tab=tags&page=1&name=11.0.7-jre-slim 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在 docker openjdk 存储库中,slim jre 11 镜像小于 70mb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM