Running Java application in Docker Container

In one of my earlier posts, we looked at how to create a Spark Application to read the Data from a CSV file. In this post, we’ll take a look at how Docker image can be created for the Spark Financial Analysis application so that it can be easily run inside a container.

The code discussed in this post is available in GitHub. This is an extension to the Spark Financial Analysis application that we created in my earlier post.

Let’s take a look at the steps required to create a Docker image for this application and push the image to Docker Hub.

Update the build.gradle to create a shadow/fat/uber jar including all the dependent jars. For this we are using the shadow jar plugin that packages the application to contain all the dependencies.

Create a Dockerfile directly under the project containing following commands. This Docker file is used to create the Docker image for the Spark Financial Analysis application. The docker image follows a layered approach with new images built upon the base images. In this case we are using openjdk as our base image. We create a new directory for storing the build artifacts and also the input CSV file containing the loan data. Finally we define the entry point to run the application.

Like this:

Related

Published by Aman Sardana

I am a technology professional working for a Fortune 300 financial services company in Greater Chicago Area. I am passionate about engineering customer centric solutions to complex business problems using software, analytics and data visualization techniques. I firmly believe that a good technical solution is the one which exceeds the customer expectation and delivers superb business results while maintaining the competitive edge.
View all posts by Aman Sardana