Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 272
Marco Avatar asked Apr 21 '15 09:04

Marco


People also ask

How do I install something in Dockerfile?

To install packages in a docker container, the packages should be defined in the Dockerfile. If you want to install packages in the Container, use the RUN statement followed by exact download command . You can update the Dockerfile with latest list of packages at anytime and build again to create new image out of it.

Can I install packages in Docker container?

To install any packages, you first need to update the OS. Step 3: After you have updated the Docker Container, you can now install the Firefox and Vim packages inside it. You can now easily use these packages through the bash itself.


1 Answers

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
like image 100
meskobalazs Avatar answered Oct 20 '22 19:10

meskobalazs