docker image设置jdk版本_使用docker安装java 8的最佳方法?

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值