Best way to install java 8 using dockers?

I have a docker file that starts on the next line

FROM java:8

I thought this should pull the image from the docker container registry and install. no?

when I run a 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 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
+4
source share
1 answer

Maybe you are missing something. Tag 8or 8-jdkwork fine:

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

You can also check by looking at the Docker file and see what it really defines JAVA_HOME. For example, see java: 8 Dockerfile

, Dockerfile, , . :

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

:

$ docker build -t myjava .

, :

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

All Articles