Best way to install java 8 using docker?

自古美人都是妖i 提交于 2019-12-30 08:27:13

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/36587850/best-way-to-install-java-8-using-docker

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!