Install JDK 8 update 172 in dockerfile with ubuntu image
Asked Answered
H

3

5

I am used to download java in my dockerfile like this :

# Install Java
ENV JAVA_VERSION_MAJOR 8
ENV JAVA_VERSION_MINOR 162
ENV JAVA_VERSION_BUILD 12
ENV JAVA_DOWNLOAD_HASH 0da788060d494f5095bf8624735fa2f1
RUN mkdir -p /usr/lib/jvm \
    && cd /usr/lib/jvm \
    && wget -nv --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-b${JAVA_VERSION_BUILD}/${JAVA_DOWNLOAD_HASH}/jdk-${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-linux-x64.tar.gz \
    && tar xf jdk-${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-linux-x64.tar.gz \
    && rm jdk-${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-linux-x64.tar.gz \
    && update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.${JAVA_VERSION_MAJOR}.0_${JAVA_VERSION_MINOR}/bin/java" 1
ENV JAVA_HOME /usr/lib/jvm/jdk1.${JAVA_VERSION_MAJOR}.0_${JAVA_VERSION_MINOR}

Apparently, oracle has released new update 8u172 and download within dockerfile is failing with ERROR 404: Not Found.

My question is , how do I find out JAVA_DOWNLOAD_HASH variable ?

Rest of variable values are clear to me :

JAVA_VERSION_MAJOR 8
JAVA_VERSION_MINOR 172
JAVA_VERSION_BUILD 11

Please note that my base docker image is : ubuntu:16.04

My installation of java within ubuntu is inspired from here

Hyperphysical answered 19/4, 2018 at 6:56 Comment(7)
You should use java hub hub.docker.com/_/javaAlvin
@AbdullahG... I do not want to use openjdkHyperphysical
I found solutionHyperphysical
I guess hash is a url parameter. 'fb4372174a714e6b8c52526dc134031e' is a hash in this url ; download.oracle.com/otn-pub/java/jdk/10.0.1+10/….Alvin
Correct. But how do we find it ?Hyperphysical
in there : oracle.com/technetwork/java/javase/downloads/…Alvin
Copy link address on download link and you will get hash ! I should have done that before. @AbdullahG thanks a lot :)Hyperphysical
H
7

I think oracle has fixed broken web8upd.

So now dockerfile specified on github works perfectly !

Just copy-pasting same dockerfile with some modifications :

FROM ubuntu:16.04

# To solve add-apt-repository : command not found
RUN apt-get -y install software-properties-common

# Install Java
RUN \
  echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
  add-apt-repository -y ppa:webupd8team/java && \
  apt-get update && \
  apt-get install -y oracle-java8-installer --allow-unauthenticated && \
  rm -rf /var/lib/apt/lists/* && \
  rm -rf /var/cache/oracle-jdk8-installer


# Define commonly used JAVA_HOME variable
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle

Please note : rm -rf /var/lib/apt/lists/* will remove all lists fetched by apt-get update.

So if you want to install more things after installing Java, remove rm -rf /var/lib/apt/lists/* otherwise you have to run apt-get update again.

Hyperphysical answered 19/4, 2018 at 7:15 Comment(1)
This answer is also leading to the timed-out scenario now : => [4/9] RUN echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | de 105.2s => => # gpg: keyring /tmp/tmp9okttpj8/secring.gpg' created => => # gpg: keyring /tmp/tmp9okttpj8/pubring.gpg' created => => # gpg: requesting key EEA14886 from hkp server keyserver.ubuntu.com => => # Error: retrieving gpg key timed out.Hypno
S
1

Please check the below code just copy and paste in dockerfile for install java

FROM ubuntu:18.04


 
# Install "software-properties-common" (for the "add-apt-repository")
RUN apt-get update && apt-get install -y \
    software-properties-common
# Add the "JAVA" ppa
RUN add-apt-repository -y \
    ppa:webupd8team/java

# Install OpenJDK-8
RUN apt-get update && \
    apt-get install -y openjdk-8-jdk && \
    apt-get install -y ant && \
    apt-get clean;

# Fix certificate issues
RUN apt-get update && \
    apt-get install ca-certificates-java && \
    apt-get clean && \
    update-ca-certificates -f \
    rm -rf /var/lib/apt/lists/* && \
    rm -rf /var/cache/oracle-jdk8-installer

# Setup JAVA_HOME -- useful for docker commandline
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
RUN export JAVA_HOME
Schoening answered 6/9, 2021 at 9:8 Comment(1)
Rawan, please note author wants oracle-jdk and not openjdk, this answer is right but irrelevantBertrand
B
1

The above solutions didn't work for me but helped to get started. Here's the one that's working for me

FileName : ubuntu_oraclejdk8

FROM ubuntu:18.04
 
# Install "software-properties-common" (for the "add-apt-repository")
RUN apt-get update && apt-get install -y \
    software-properties-common

## Install Oracle's JDK
# add oracle jdk repository
RUN add-apt-repository ppa:ts.sch.gr/ppa \
# accept oracle license
  && echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections \
  && echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections \
  && apt-get update \
# install oracle jdk 8 and make it default
  && apt-get -y install oracle-java8-installer \
  && apt-get -y install oracle-java8-set-default \
# clean up
  && apt-get clean all \
  && rm -rf /var/lib/apt/lists/*
CMD ["bash"]

Docker steps to make it work

$ docker build -t ubuntu_oraclejdk8 - < ubuntu_oraclejdk8
$ docker run -it ubuntu_oraclejdk8
Bertrand answered 1/1, 2022 at 16:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.