Docker 图像 - 类型.修身vs修身弹力vs弹力vs高山

2022-01-14 00:00:00 docker dockerfile java

我正在寻找一个 docker 映像来构建一个 java 应用程序并查看可用的 OpenJDK 映像的变体.我在看这里 https://github.com/docker-library/openjdk/tree/master/8/jdk 并查看 alpine、slim 和 windows.这些之间有什么区别以及每个变体给出什么?

I am looking to pick up a docker image to build a java app and looking at the variants of the OpenJDK images available. I am looking here https://github.com/docker-library/openjdk/tree/master/8/jdk and see alpine, slim and windows. What are the differences between these and what does each variant give?

推荐答案

每个 docker 库文档(下面的引用和链接),这里是一个摘要:

Per docker library docs (quote and links below), here's a summary:

  • openjdk:<版本>

事实上的形象.如果不确定,请使用它.

The defacto image. Use it if unsure.

  • openjdk:-busteropenjdk:-stretchopenjdk:-jessie

busterjessiestretch 是 Debian 并指明映像基于哪个发行版.

buster, jessie or stretch are the suite code names for releases of Debian and indicate which release the image is based on.

  • openjdk:-alpine

同样,此映像基于 Alpine Linux,因此是一个非常小的基础映像.如果您需要图像尺寸尽可能小,建议使用.需要注意的是它使用了一些不寻常的库,但对于大多数软件来说应该不是问题.如有疑问,请查看以下官方文档.

Similarly, this image is based on the Alpine Linux, thus being a very small base image. It is recommended if you need an image size is as small as possible. The caveat is that it uses some unusual libs, but shouldn't be a problem for most software. In doubt, check the official docs below.

  • openjdk:(从 12 开始),openjdk:-oracleopenjdk:;-oraclelinux7

  • openjdk:<version> (from 12 onwards), openjdk:<version>-oracle and openjdk:<version>-oraclelinux7

openjdk:12 开始的默认镜像以及 -oracle-oraclelinux7 变体都是基于官方的 Oracle Linux 7 映像.默认映像中的 OpenJDK 二进制文件以及 -oracle-oraclelinux7 变体由 Oracle 构建,并来自 OpenJDK 社区.

Starting with openjdk:12 the default image as well as the -oracle and -oraclelinux7 variants are based on the official Oracle Linux 7 image. The OpenJDK binaries in the default image as well as the -oracle and -oraclelinux7 variants are built by Oracle and are sourced from the OpenJDK community.

  • openjdk:-slim

此图像仅包含运行 Java 所需的最少包(例如,缺少许多与 UI 相关的 Java 库).除非您在仅 openjdk 映像将被部署并且您有空间限制的环境中工作,否则建议使用默认映像而不是此映像.

This image only contains the minimal packages needed to run Java (and is missing many of the UI-related Java libraries, for instance). Unless you are working in an environment where only the openjdk image will be deployed and you have space constraints, the default image is recommended over this one.

  • openjdk:-windowsservercore

此映像基于 Windows Server Core (microsoft/windowsservercore).

This image is based on Windows Server Core (microsoft/windowsservercore).


完整文档(此处显示的版本,这里是最新版本):

openjdk 图像有多种风格,每一种都是为具体用例.

Image Variants

The openjdk images come in many flavors, each designed for a specific use case.

这是事实上的图像.如果您不确定自己的需求是,你可能想用这个.它被设计为同时使用作为一个扔掉的容器(安装你的源代码并启动容器来启动您的应用程序),以及构建其他应用程序的基础图像关闭.

This is the defacto image. If you are unsure about what your needs are, you probably want to use this one. It is designed to be used both as a throw away container (mount your source code and start the container to start your app), as well as the base to build other images off of.

其中一些标签可能包含像 jessie 或拉伸这样的名称.这些是版本的套件代号Debian 并指出哪个发布图像是基于.

Some of these tags may have names like jessie or stretch in them. These are the suite code names for releases of Debian and indicate which release the image is based on.

此图像基于流行的 Alpine Linux项目,在 alpine 官方提供图片.Alpine Linux 要小得多比大多数分发基础图像(~5MB),因此导致很多总体而言,图像更窄.

This image is based on the popular Alpine Linux project, available in the alpine official image. Alpine Linux is much smaller than most distribution base images (~5MB), and thus leads to much slimmer images in general.

当最终图像大小为尽可能小.需要注意的主要警告是它确实使用 musl libc 而不是 glibc 和朋友,那么肯定软件可能会遇到问题,具体取决于其 libc 的深度要求.但是,大多数软件都没有这个问题,所以这个变体通常是一个非常安全的选择.查看这个黑客新闻评论线程更多讨论可能出现的问题和一些赞成/反对使用基于 Alpine 的图像的比较.

This variant is highly recommended when final image size being as small as possible is desired. The main caveat to note is that it does use musl libc instead of glibc and friends, so certain software might run into issues depending on the depth of their libc requirements. However, most software doesn't have an issue with this, so this variant is usually a very safe choice. See this Hacker News comment thread for more discussion of the issues that might arise and some pro/con comparisons of using Alpine-based images.

为了最小化图像大小,额外的相关工具并不常见(例如 gitbash)要包含在基于 Alpine 的图像中.使用以此图像为基础,在自己的 Dockerfile 中添加你需要的东西(参见 alpine 图像描述 举例说明如何如果您不熟悉,请安装软件包.

To minimize image size, it's uncommon for additional related tools (such as git or bash) to be included in Alpine-based images. Using this image as a base, add the things you need in your own Dockerfile (see the alpine image description for examples of how to install packages if you are unfamiliar).

此图像基于 Windows Server Core(microsoft/windowsservercore).因此,它仅适用于该图像的位置,例如Windows 10 专业版/企业版(周年纪念版)或 Windows服务器 2016.

This image is based on Windows Server Core (microsoft/windowsservercore). As such, it only works in places which that image does, such as Windows 10 Professional/Enterprise (Anniversary Edition) or Windows Server 2016.

有关如何让 Docker 在 Windows 上运行的信息,请参阅微软提供的相关快速入门"指南:

For information about how to get Docker running on Windows, please see the relevant "Quick Start" guide provided by Microsoft:

  • Windows Server 快速入门
  • Windows 10 快速入门

这个镜像安装了 OpenJDK 的 -headless 包,所以是缺少许多与 UI 相关的 Java 库和一些常用包包含在默认标签中.它只包含最小的包需要运行 Java.除非你在一个环境中工作只有 openjdk 镜像会被部署并且你有空间限制,我们强烈推荐使用这个默认镜像存储库.

This image installs the -headless package of OpenJDK and so is missing many of the UI-related Java libraries and some common packages contained in the default tag. It only contains the minimal packages needed to run Java. Unless you are working in an environment where only the openjdk image will be deployed and you have space constraints, we highly recommend using the default image of this repository.

相关文章