为什么 Java 11 基础 Docker 镜像如此之大?(openjdk:11-jre-slim)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/53375613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why is the Java 11 base Docker image so large? (openjdk:11-jre-slim)
提问by radistao
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 被宣布为最新的 LTS 版本。因此,我们正在尝试基于此 Java 版本启动新服务。
However, the base Docker image for Java 11 is much larger than the equivalent for Java 8:
但是,Java 11 的基础 Docker 镜像比 Java 8 的等价镜像大得多:
openjdk:8-jre-alpine
: 84 MBopenjdk:11-jre-slim
: 283MB
openjdk:8-jre-alpine
: 84 MBopenjdk:11-jre-slim
: 283MB
(I'm considering only the official OpenJDKand the most lightweightimages for each Java version.)
(我只考虑官方 OpenJDK和每个 Java 版本最轻量级的图像。)
Deeper digging uncovered the following "things":
深入挖掘发现了以下“事情”:
the
openjdk:11-jre-slim
image uses the base imagedebian: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 largerthanopenjdk8-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
的
openjdk:11-jre-slim
图像使用基本图像debian:sid-slim
。这带来了2个问题:这比 60 MB 大
alpine:3.8
在Debian的
sid
版本是不稳定
openjdk-11-jre-headless
安装在镜像中的包比(在运行的 Docker 容器内)大 3 倍openjdk8-jre
: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/
更深入地我发现了这种沉重的“根源”——它
modules
是 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 sidversion 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 modulesfile which brings 135 MB in OpenJDK 11?
为什么
alpine
不再用作 Java 11 超薄镜像的基础镜像?为什么LTS Java 镜像使用的是不稳定的sid版本?
为什么 OpenJDK 11 的 slim/headless/JRE 包与类似的 OpenJDK 8 包相比如此之大?
- 在 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
采纳答案by valiano
Why is
alpine
not used any more as a base image for Java 11 slim images?
为什么
alpine
不再用作 Java 11 超薄镜像的基础镜像?
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. The musl OpenJDK port is being developed under OpenJDK's Portolaproject.
Alpine 使用 musl libc,而不是大多数 Linux 使用的标准 glibc,这意味着 JVM 必须与 musl libc 兼容才能支持 vanilla Alpine。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. 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.
从 JDK 11 GA 开始,此页面上先前提供的 Alpine Linux 版本已被删除。它不是生产就绪的,因为它没有经过足够彻底的测试,无法被视为 GA 版本。请使用早期访问的 JDK 12 Alpine Linux 版本来代替它。
The only stable OpenJDK versions for Alpine currently are 7 and 8, provided by the IcedTeaproject.
目前,Alpine 唯一稳定的 OpenJDK 版本是 7 和 8,由IcedTea项目提供。
However - if you're willing to consider other than the official OpenJDK, Azul's ZuluOpenJDK offers a compelling alternative:
但是 - 如果您愿意考虑官方 OpenJDK 以外的其他产品,Azul 的 ZuluOpenJDK 提供了一个引人注目的替代方案:
- 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).
- 它在 Alpine musl 上支持Java 11(截至撰写本文时为 11.0.2 版);
- 它是经过认证的 OpenJDK 构建,使用 OpenJDK TCK 合规套件进行验证;
- 它是免费的、开源的并且支持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! It could be grabbed on Alpine using:
2019 年 3 月 6 日更新:截至昨天,openjdk11
在 Alpine 存储库中可用!可以使用以下方法在 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. Kudos and huge thanks to the Alpine team.
该包基于jdk11u
OpenJDK 分支以及来自项目 Portola 的移植修复,引入了以下PR。非常感谢 Alpine 团队。
Why is the unstable sidversion 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:
https://github.com/docker-library/openjdk/issues/237
这是一个公平的问题/要求。实际上有一个在稳定的 Debian 版本上提供 Java 11 的公开票: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).
18 年 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? What is this modulesfile which brings 135 MB in OpenJDK 11?
为什么 OpenJDK 11 的 slim/headless/JRE 包与类似的 OpenJDK 8 包相比如此之大?在 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. This article from Oracle gives a very detailed introduction to this feature:
https://www.oracle.com/corporate/features/understanding-java-9-modules.html
Java 9 引入了模块系统,与 jar 文件相比,这是一种新的改进方法,用于对包和资源进行分组。Oracle的这篇文章非常详细的介绍了这个特性: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.
该modules
文件捆绑了 JRE 附带的所有模块。完整的模块列表可以用java --list-modules
. 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.jar
和tools.jar
已弃用,除此之外,因此在考虑modules
与 9 之前的 OpenJDK 版本相比时的大小时rt.jar
,tools.jar
应该减去和的大小(它们应该占用大约 80MB 的总和) .
回答by radistao
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: slimimages 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.)
回答by Javier Aviles
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