使用docker安装java 8的最佳方法? [英] Best way to install java 8 using docker?

查看:4015
本文介绍了使用docker安装java 8的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从以下行开始的docker文件



FROM java:8



我以为这是从docker容器注册表中提取图像并进行安装。没有?



当我在我的容器内运行java命令时,我收到以下错误

 code>错误:JAVA_HOME未设置,您的PATH中找不到java命令。 

使用docker安装java 8(openjdk版本)最简单和最好的方法是什么? p>

更新:

 运行apt-get install -y -no-install-recommends-software-properties-common 
RUN add-apt-repository -y ppa:openjdk -r / ppa
RUN apt-get update
RUN apt- get install -y openjdk-8-jdk
运行apt-get install -y openjdk-8-jre
运行update-alternatives --config java
RUN update-alternatives --config javac


解决方案

也许你错过了一些东西。
8 标签或 8-jdk 正常工作:

  $ docker run -ti java:8-jdk 
root @ ea4ae4cf642e:/#echo $ JAVA_HOME
/ usr / lib / jvm / 8-openjdk-amd64

您还可以通过查看Dockerfile来确认它确实定义了 JAVA_HOME 。例如,请参阅 java:8 Dockerfile



另外,Dockerfile最简单的形式当然会得到同样的结果。即:

  FROM java:8-jdk 
CMD [/ bin / bash]

以下列方式构建:

 code> $ docker build -t myjava。 

然后执行它:

  $ docker run -ti myjava:latest bash 
root @ 3c35f7d2d94a:/#echo $ JAVA_HOME
/ usr / lib / jvm / java-8-openjdk-amd64


I have a dockerfile that starts with the following line

FROM java:8

I thought this is supposed to pull the image from the docker container registry and install. no?

when I run the java command inside my container I get the following error

ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

What is the easiest and the best way to install java 8(openjdk version) using docker?

UPDATE:

RUN apt-get install -y --no-install-recommends software-properties-common
RUN add-apt-repository -y ppa:openjdk-r/ppa
RUN apt-get update
RUN apt-get install -y openjdk-8-jdk
RUN apt-get install -y openjdk-8-jre
RUN update-alternatives --config java
RUN update-alternatives --config javac

解决方案

Perhaps you're missing something. 8 tag or 8-jdk are working fine:

$ docker run -ti java:8-jdk
root@ea4ae4cf642e:/# echo $JAVA_HOME
/usr/lib/jvm/java-8-openjdk-amd64

You can also verify by looking at the Dockerfile and see that it indeed defines JAVA_HOME. For example, see java:8 Dockerfile

Also, The simplest form of Dockerfile will, of course, evaluate to the same result. i.e:

FROM java:8-jdk
CMD ["/bin/bash"]

And building in the following way:

$ docker build -t myjava .

Then, executing it:

$ docker run -ti myjava:latest bash
root@3c35f7d2d94a:/# echo $JAVA_HOME
/usr/lib/jvm/java-8-openjdk-amd64

这篇关于使用docker安装java 8的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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