My journey: Dockerized Java on Apache Mesos Container cluster on Azure – Setup a Docker (Part II)

September 1, 2016

no comments

At the previous post we manage to create Automated Build Docker Repository. Now we need to create and configure the Docker.

Now we have the skeleton and it’s the same skeleton for all Docker types, whether it will hold Java / Python / Scala / .NET Core container, the skeleton is the same.

Environment Setup – Linux

So, we need an environment to work with the Dockers. I myself prefer to work with the Linux Server for that, I sure that there are another alternatives. Sill the terminal approach more clean to do so.

I’m using Ubuntu 16.04 server on Oracle VirtualBox. (if you need assistance with that see YouTube link for it).

Now that we have the server we need to setup the Docker on it. Please refer for this process to the Docker Hub documentation – Installation on Ubuntu. (each OS have a  different guide, be sure you’re using the right one)

Now that the environment exist we’re good to start

Build the Docker Image.

We don’t have to start from scratch for this journey I chose to run Java Application on Ubuntu OS. Because this is our base line we can find an existing “starting point” Docker on the Docker Repositories.

The Docker commands can be found on – see.

Step 1: Run over the existing images & containers on the machine.

When the we installed the Docker engine (on the previous section) the Docker environment automatically also downloaded a test image named “hello-world” with the latest version.

To view the existing images please run:

## Retrieve all the existing images on the machine
docker images

The result will be all the existing images on the machine.


To view the existing containers please run:

## Retrieve all the existing containers on the machine
docker ps -a

The result will be all the existing containers on the machine.


Step 2: Build the Java Application Docker.

So, we going to create a Java Docker. By that we need:

  1. A Docker that can run Java – JVM required.
  2. A Java application – Jar to execute.

For now we not talking about application which required an additional drivers installation (still it’s not an issue, just add it to the Docker).

Step 3: Setup the Java Docker infrastructure.

We don’t need to start from scratch, let’s go back to the Docker Hub portal and click on the Explore link and search for ubuntu.


Click on the Docker DETAILS link. You will see the Docker details, comments and Docker Pull Command.


To pull the Docker to our machine, log to the Linux machine and log to the Docker work space.

## Login to the Docker work space
sudo docker login
# Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to to create one.
Username: {Set your username}
Password: {Set your password}
# Login Succeeded

Now you logged into the work space, run the Docker pull command. In our case  “docker pull ubuntu“.

## Download the Ubuntu Docker image
docker pull ubuntu

The will be (see that the latest tag is pull because  specific tag not specified)


Now when running once again the command to see the existing images we will get


Next, run the Docker image by using the next run command.

## Run local Ubuntu Docker image
docker run -t -i ubuntu /bin/bash

See that now you inside the running docker, as root user. The command line will show something like root@5d2427292d2b:/#.  Where the 5d2427292d2b is the container id.

docker_image_run _console

This image missing java on it , which in this case is required for our session.

## Add missing apt-get software common properties
apt-get install software-properties-common

## Add to apt-get the Java Repository
add-apt-repository ppa:webupd8team/java

## Update the apt-get 
apt-get update

## Install Oracle-Java-8
apt-get install oracle-java8-installer

When Done run the next command to validate the Java installation

## Retrieve Java version
java -version


Step 4: Place the Java Jar into the Docker.

I create a simple Java application “Hello World From”, which can get external parameters and not.

import com.amourshmuel.docker.utils.StdOut;

public class Program {

    public static void main(String[] args){
            StdOut.println("Hello World from: "+ args[0].toString() );
            StdOut.println("Hello World from: Shmuel");

The Java Application source code and output located on git: HelloWordFrom. The executable jar located on com.amourshmuel.docker.hellowordfrom-1.0-SNAPSHOT.jar.

## Download the Jar

## Rename the Jar
mv com.amourshmuel.docker.hellowordfrom-1.0-SNAPSHOT.jar helloworldfrom.jar

## Test it
java -jar helloworldfrom.jar 'Amour Shmuel'

## The output will be
## Hello World from: Amour Shmuel

Exit the Docker controller

## Exit the Controller

At this stage with have the Local Docker image with:

  1. Oracle Java 8 installed.
  2. My Java Application installed on the root.

Step 5: Commit the Build changes.

## Commit the live container to the repository
docker commit -m "my comment" -a "Amour shmuel" 5d2427292d2b amourshmuel/docker_java_app

** See that I didn’t specified any Tag, in this case it will be set to the [latest] Tag. There is an option to pass it like [amourshmuel/docker_java_app:1.0.0] when 1.0.0  is  the Tag I decided on

Step 6: Build the Docker Image

Because we’re using “Automated Build Docker” it will required later on an additional Dockerfile, but let’s deal with it later.

## Create a new directory (like 'docker_java_app') and enter it
sudo mkdir docker_java_app 
cd docker_java_app 

## Create new Docker file, I'm using the default name Dockerfile
sudo touch Dockerfile 

## vi / vim or nano the file and place the next lines into it
FROM amourshmuel/docker_java_app
ENTRYPOINT  ["java", "-jar", "helloworldfrom.jar"]

** See that I used [FROM amourshmuel/docker_java_app], if a specific tag was reguired it should be like [FROM amourshmuel/docker_java_app:{Tag}]

Run the build command

## Build it
docker build -t amourshmuel/docker_java_app .

** Also here the build if for the latest one so no Tag given
** I’m using the  default Dockerfile name, and because of that the command ending with DOT [.]  and not the the file name

Step 7: Test the Docker Image.

## Run a container with not parameters
docker run -t -i amourshmuel/docker_java_app
## The result will be "Hello World from: Shmuel"

## Run a container with parameters
docker run -t -i amourshmuel/docker_java_app 'Amour Shmuel'
## The result will be "Hello World from: Amour Shmuel"

Step 8: Push the image to the Docker-Hub.

Before doing it let’s understand the responsibility between the Docker-Hub and the Git-Hub

The Docker-Hub: holds the Repository image binary data.
The Git-Hub: holds the Dockerfile(s) and scripts.

The Docker-Hub gets notifications from the Git-Hub when changes occur and if ‘Automated-Build’ has triggers for changes the build will re-run (re-build).

## Push the Repository image to the Git-Hub
docker push amourshmuel/docker_java_app

The push result will provide {Tag}:digest:{digest_sequence} size: {size}.
like: latest: digest: sha256:e191cad8f469f3c49440803e627947869c9cbc898a9792fc1c2a8b76e81697fb size: 1777


Step 9: Enable the Automated Build.

The Docker-Hub: holds the Repository image binary data.
The Git-Hub: holds the Dockerfile(s) and scripts.

To do so we need to navigate to the “Build Settings” on the on the Automated Build repository – Docker-Hub website.

The first line it refer to the master branch with the latest tag. see that the Docker Location set to /.  That mean that the Docker-Hub expects the Dockerfile to be located on the root of the attached Git-Hub repository. This can be modified (usually when supporting multiple Tags).

So, on the related Git-Hub we will place a Dockerfile with the same lines like we used on the linux machine – just load it to the root git folder.

After you set the Dockerfile on the Git-Hub (give it a minute or two) your Dockerfile content will be show on the  “Dockerfile” on the on the Automated Build repository – Docker-Hub website.


More than that navigate to the “Build Details” on the on the Automated Build repository – Docker-Hub website. We will see the Automated Build results.

  • The current build identifiers
  •  The Build Code
  • The used Dockerfile
  • And the execution Log



We have a successful “Automated Build” ready to use!!!

So, now we need hosting container host, for that on the next post we’ll use the Apache Mesos cluster when it’s located on Azure cloud.

My journey: Dockerized Java on Apache Mesos Container cluster on Azure – Setup Apache Mesos on Azure

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>