如何使用 Dockerfile 安装特定版本的 Java 8

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29768304/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 08:33:55  来源:igfitidea点击:

How to install a specific version of Java 8 using Dockerfile

javadockerdockerfile

提问by Marco

I am trying to build a Docker Container (using a Dockerfile) with a specific version of Java 8 on it. A lot of the examples target the latest release.

我正在尝试使用特定版本的 Java 8 构建一个 Docker 容器(使用 Dockerfile)。许多示例都针对最新版本。

RUN add-apt-repository -y ppa:webupd8team/java
RUN apt-get update -y

RUN echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
RUN apt-get install -y oracle-java8-installer

I have a need where i want to control the specific version of Java that my container is provisioned. Any hint on how to achieve this? For Example Java 8 update 31.

我需要控制为我的容器提供的特定 Java 版本。关于如何实现这一目标的任何提示?例如 Java 8 更新 31。

采纳答案by meskobalazs

As most PPA packages pack the latest stable version, I would recommend installing Java manually from Oracle, just like in this answer.

由于大多数 PPA 包都包含最新的稳定版本,我建议从 Oracle 手动安装 Java,就像在这个答案中一样

You can do all the work in the script too, the steps are:

您也可以在脚本中完成所有工作,步骤是:

  • get the tarball with wget,
  • untar it with tar -xz,
  • use update-alternativesto set is as default
  • 获取 tarball wget
  • 解压它tar -xz
  • 用于update-alternatives设置为默认值

回答by Mark O'Connor

Another option is to use the official Java image from the Docker Hub Registry

另一种选择是使用来自Docker Hub Registry的官方 Java 镜像

Admittedly it doesn't offer the Oracle JDK due to licensing restrictions, but it's the simplest way to integrate Java into your Docker workflow.

诚然,由于许可限制,它不提供 Oracle JDK,但它是将 Java 集成到 Docker 工作流中的最简单方法。

回答by Anand Prakash

For Docker Container OS: Cent 6.6

对于 Docker 容器操作系统:Cent 6.6

Use this command in your Dockerfile to update your JDK version to 1.8:

在 Dockerfile 中使用此命令将 JDK 版本更新为 1.8:

RUN touch /var/lib/rpm/* \ 
 && yum -y install java-1.8.0-openjdk-devel