Skip to content

Instantly share code, notes, and snippets.

@asolera
Created January 11, 2021 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asolera/d185ce20ddd39865ab16a0e6acba1414 to your computer and use it in GitHub Desktop.
Save asolera/d185ce20ddd39865ab16a0e6acba1414 to your computer and use it in GitHub Desktop.
Install Java (JDK8) inside Dockerfile from another image
FROM another/image:example
# Credits to https://stackoverflow.com/a/64062083
# some dockerfile commands...
ENV JAVA_FOLDER java-se-8u41-ri
ENV JVM_ROOT /usr/lib/jvm
ENV JAVA_PKG_NAME openjdk-8u41-b04-linux-x64-14_jan_2020.tar.gz
ENV JAVA_TAR_GZ_URL https://download.java.net/openjdk/jdk8u41/ri/$JAVA_PKG_NAME
RUN apt-get update && apt-get install -y wget && rm -rf /var/lib/apt/lists/* && \
apt-get clean && \
apt-get autoremove && \
echo Downloading $JAVA_TAR_GZ_URL && \
wget -q $JAVA_TAR_GZ_URL && \
tar -xvf $JAVA_PKG_NAME && \
rm $JAVA_PKG_NAME && \
mkdir -p /usr/lib/jvm && \
mv ./$JAVA_FOLDER $JVM_ROOT && \
update-alternatives --install /usr/bin/java java $JVM_ROOT/$JAVA_FOLDER/bin/java 1 && \
update-alternatives --install /usr/bin/javac javac $JVM_ROOT/$JAVA_FOLDER/bin/javac 1 && \
java -version
# other dockerfile commands...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment