Dockers – How to Get Started with Java8 Dev Environment

This article represents take away code samples and tips on how to setup Java8 container using Dockers and get started. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos.

Following are the key points described later in this article:

  • Java 8 Image Dockerfile
  • Install Scripts to Install and Start Java8 Env


Java 8 Image Dockerfile

Following is Dockerfile for creating Java8 image. Name the file as java8_base.df.

# Base is the Centos environment
FROM centos:centos6

# Make the directories under which Java 8 will get installed
RUN mkdir /opt/jdk
RUN cd /opt

# Install wget and tar which will be used to download and unzip Java8 files
RUN yum -y install wget tar

# Download the files
RUN wget --header "Cookie: oraclelicense=accept-securebackup-cookie"

# Unzip in /opt/jdk folder
RUN tar -zxf jdk-8u5-linux-x64.tar.gz -C /opt/jdk

# Set the path for Java and Javac
RUN update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_05/bin/java 100
RUN update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.8.0_05/bin/javac 100


Install Scripts to Install and Start Java8 Env

Following scripts perform following two activities:

  • If Java8 image, java8_base, is not found, it builds the Java8 image. This is one time activity.
  • Stops and starts the container

One may name the script as “” and use it such as “ j8” where j8 is the name of the container. Make sure to put both of the above files, java8_base.df and in the same folder.


if [ $# == 0 ]; then
  echo "This script expect container name argument. Example: ./ j8"
  exit 100

docker stop $1;docker rm $1

# Build Java8 image if it does not exists
if [ `docker images $j8_image | wc -l` -lt 2 ]; then
  echo "Docker Image $j8_image do not exist..."
  echo "Builing docker image $j8_image"
  if [ -f $j8_df ]; then
    docker build -t $j8_image -f $j8_df .
    echo "Can't find Dockerfile $j8_df in the current location"
    exit 200

docker run --privileged=true -ti -dP --name $1 -v /c/Users:/mnt/Users $j8_image /bin/bash
docker exec -ti $1 /bin/bash


Ajitesh Kumar
Follow me

Ajitesh Kumar

I have been recently working in the area of Data analytics including Data Science and Machine Learning / Deep Learning. I am also passionate about different technologies including programming languages such as Java/JEE, Javascript, Python, R, Julia, etc, and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data, etc. For latest updates and blogs, follow us on Twitter. I would love to connect with you on Linkedin. Check out my latest book titled as First Principles Thinking: Building winning products using first principles thinking. Check out my other blog,
Posted in DevOps, Dockers, Java. Tagged with , , .

Leave a Reply

Your email address will not be published. Required fields are marked *