Monday, July 20, 2015

How to install Java 8 & 7 on Ubuntu using Docker


There is no any official java docker images available for oracle java versions. If you need oracle java for your docker images, either you need to use unofficial docker which has java installed for you(there are plenty) or you can do it for your self, means you can install java on your own docker image which use any ubuntu based image as based image. Here I am explaining how you can install java 8 and java 7 on an ubuntu image.

Here is the docker file content which install oracle java 8(JDK1.8)on ubuntu trusty image.
# Pull base image. if you use "latest" instead of "trusty",
# you will use latest ubuntu images as base image
FROM ubuntu:trusty

# Set maintainer details
MAINTAINER SHAMEERA

# Install prerequisites
RUN apt-get update
RUN apt-get install -y software-properties-common

# Install java8
RUN add-apt-repository -y ppa:webupd8team/java
RUN apt-get update
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
After you build and run this docker images. you can see the java version by using "java -version" command. It will output following.
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

You can use this docker image as your docker image's based image by using
FROM shameera/java8_trusty:latest
here is the docker hub link

Here is the docker file content which install oracle java 7(JDK1.7) on ubuntu trusty image.
# Pull base image. if you use "latest" instead of "trusty",
# you will use latest ubuntu images as base image
FROM ubuntu:trusty

# Set maintainer details
MAINTAINER SHAMEERA

# Install prerequisites
RUN apt-get update
RUN apt-get install -y software-properties-common

# Install java7
RUN add-apt-repository -y ppa:webupd8team/java
RUN apt-get update
RUN echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
RUN apt-get install -y oracle-java7-installer

"java -version" on this image outputs following.
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)


You can use this docker image as your docker image's based image by using
FROM shameera/java7_trusty:latest
Here is the docker hub link

Sample Text

Website counter

Categories