为什么Java 11基础Docker镜像如此之大? (的openjdk:11-JRE-苗条) [英] Why is the Java 11 base Docker image so large? (openjdk:11-jre-slim)

查看:2158
本文介绍了为什么Java 11基础Docker镜像如此之大? (的openjdk:11-JRE-苗条)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 11被宣布为最新的LTS版本。因此,我们正在尝试基于此Java版本启动新服务。

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

但是,Java 11的基本Docker镜像远远大于Java 8的等效镜像:

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

  • openjdk:8-jre-alpine: 84 MB

openjdk:11-jre-slim 283 MB

(我只考虑 官方OpenJDK 每个Java版本的最轻量级 图片。)

(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:


  • 这比60美元大于 alpine:3.8

Debian sid 版本不稳定

the Debian sid versions are unstable

openjdk-11-jre-headless 图片中安装的软件包比 openjdk8-jre 大3倍 $ c>(在内部运行Docker容器):

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/
    


    更深入地我发现了t的根他的沉重 - 这是JRE的模块文件:

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


    # ls -lhG /usr/lib/jvm/java-11-openjdk-amd64/lib/modules
    -rw-r--r-- 1 root 135M Oct 17 07:31 /usr/lib/jvm/java-11-openjdk-amd64/lib/modules
    



  • 所以,现在出现的问题是:

    So, now the questions which came:


    • 为什么 alpine 不再用作Java 11苗条图像的基本图像?

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

    为什么不稳定的 sid 版本用于LTS Java图像?

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

    为什么苗条/ OpenJDK 11的无头/ JRE包与类似的OpenJDK 8包相比如此之大?

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


    • 这个模块文件是什么,它在OpenJDK 11中带来135 MB?

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

    请不要讨论并提议:


    • 来自其他(匿名)开发人员等的自定义图像。

    • custom images from other (anonymous) developers etc.

    其他(不稳定/非LTS)Java版本 - 我们想要推进官方LTS版本(例如,不建议基于 alpine 的OpenJDK 12图像,因为Java 12将不是LTS)。

    other (unstable/non-LTS) Java versions - we want to move forward with official LTS versions (e.g. don't propose OpenJDK 12 images based on alpine, because Java 12 won't be LTS).

    推荐答案


    为什么 alpine 不再用作Java 11苗条图像的基本图像?

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

    这是因为,遗憾的是,目前还没有官方稳定OpenJDK 11为Alpine构建。

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

    Alpine使用musl libc,而不是大多数Linux使用的标准glibc,这意味着JVM必须兼容musl libc支持香草阿尔卑斯山。 OpenJDK端口正在OpenJDK的 Portola 项目下开发。

    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.

    当前状态总结在 OpenJDK 11页



    自JDK起,此页面上以前提供的Alpine Linux版本已被删除11 GA。它不是生产就绪的,因为它没有经过足够的测试,不能被认为是GA版本。请使用早期访问的JDK 12 Alpine Linux版本。

    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.


    据我所知,目前唯一适用于Alpine的OpenJDK版本是7和8。

    The only stable OpenJDK versions for Alpine currently, to my knowledge, are 7 and 8.


    为什么不稳定的 sid 用于LTS Java图像的版本?

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

    这是一个公平的问题/请求。实际上是一个在稳定的Debian版本上提供Java 11的开放票:

    https://github.com/docker-library/openjdk/issues/237

    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


    为什么苗条/无头OpenJDK 11的/ JRE包与类似的OpenJDK 8包相比如此之大?什么是模块文件,它在OpenJDK 11中带来135 MB?

    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引入了模块系统,与jar文件相比,这是一种用于对包和资源进行分组的新的改进方法。 Oracle的这篇文章对此功能进行了非常详细的介绍:

    https://www.oracle.com/corporate/features/understanding-java-9-modules.html

    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

    modules 文件捆绑了JRE附带的所有模块。可以使用 java --list-modules 打印完整的模块列表。 modules 确实是一个非常大的文件,并且如评论所述,它包含所有标准模块,因此非常臃肿。

    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.

    但有一点需要注意的是,它取代了 rt.jar tools.jar ,这些都被弃用了其他的东西,所以当与9前OpenJDK版本进行比较时,当计算 modules 的大小时, rt.jar tools.jar (它们应该占用80MB左右)。

    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).

    这篇关于为什么Java 11基础Docker镜像如此之大? (的openjdk:11-JRE-苗条)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆