Marco
Marco

Reputation: 15929

How to install a specific version of Java 8 using Dockerfile

I am trying to build a Docker Container (using a Dockerfile) with a specific version of Java 8 on it. A lot of the examples target the latest release.

RUN add-apt-repository -y ppa:webupd8team/java
RUN apt-get update -y

RUN echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
RUN apt-get install -y oracle-java8-installer

I have a need where i want to control the specific version of Java that my container is provisioned. Any hint on how to achieve this? For Example Java 8 update 31.

Upvotes: 9

Views: 23608

Answers (3)

Anand Prakash
Anand Prakash

Reputation: 341

For Docker Container OS: Cent 6.6

Use this command in your Dockerfile to update your JDK version to 1.8:

RUN touch /var/lib/rpm/* \ 
 && yum -y install java-1.8.0-openjdk-devel

Upvotes: 0

Mark O'Connor
Mark O'Connor

Reputation: 77961

Another option is to use the official Java image from the Docker Hub Registry

Admittedly it doesn't offer the Oracle JDK due to licensing restrictions, but it's the simplest way to integrate Java into your Docker workflow.

Upvotes: 0

meskobalazs
meskobalazs

Reputation: 16041

As most PPA packages pack the latest stable version, I would recommend installing Java manually from Oracle, just like in this answer.

You can do all the work in the script too, the steps are:

  • get the tarball with wget,
  • untar it with tar -xz,
  • use update-alternatives to set is as default

Upvotes: 9

Related Questions