Dockerizing any JAVA Application

We have been talking a lot about digital transformation and how it has been transforming the world at large. Cloud and DevOps, which are at the core of this digital transformation, is taking business productivity of many enterprises to the next level. Using Docker as a cloud tool or in general terms, Dockerizing any application has brought huge changes in the way the developers and software publishers have been releasing their applications.
Why Docker: Importance and advantages of Dockerizing your application

Docker is a lightweight open source tool which can be used for containerization. The lightweight nature along with the simple workflow process it follows makes it a real lifesaver for the developers and system admins. The basic objective of using Docker is to make an application which can be packed and shipped without any hassle to work on different environments.

Docker along with container saves developers from much hassles. It was a problematic factor for the developers to decide if the code they are packing, shipping and trying to run on a different environment is at all going to run. Docker made this process easy by the use of containers. Containers allow developers to simply pack an application in a very convenient manner with all its libraries and other dependencies and ship the whole package to a completely different environment. This process makes sure that the application is going to run on Linux kernel, regardless of the machine which has been used to write and test the codes, in the first place.

For more on containerization with Docker, read…..

Dockerizing an application entails converting an application to run within a Docker container. The process is pretty straight-forward barring a few problems that need to be resolved each time.

Steps to Dockerize a JAVA application:

At LovesCloud, we have successfully used DevOps to transform the development cycle for many of our customers. Now, it’s time to see how we Dockerize a JAVA application.

Please follow the below steps carefully as we take you through the not-so-cumbersome process of Dockerizing JAVA applications.

    • Ssh to your Ubuntu Workstation with Docker and Git installed in it.
      After SSH to your Workstation, Type the following command:-

      $ sudo su
    • Clone the Git repo that contains the Java code and run following commands:-
      # mkdir /home/ubuntu/Docker
      # cd /home/ubuntu/Docker/
      # git clone
    • Once the Git Repo cloning is successful, run the following commands:-
      # cd java-docker/
      # mvn clean
      # mvn package
    • Now create a Dockerfile to Dockerize the JAVA application
      # vim Dockerfile
      Add the below content to the Dockerfile
      FROM tomcat:8.0.51-jre8-alpine
      COPY target/ /target
      CMD java -jar /target/dependency/webapp-runner.jar /target/*.war

Press esc key and type :wq and Press Enter to Save and Exit from Vim editor.

  • Build the docker image by running the below command and then viewing the images:-
    Note: in the below command, replace with your name.

    # dockerbuild . -t java-app-
    # docker images 

  • Run a Docker container from the created Image.
    # docker run -d -p 80:8080 --name -java-app java-app-
    # docker ps

    The JAVA Docker Container running on port 80, and can be accessed from the public IP of your AWS Workstation on default Port 80


  • To stop the Docker container by running the below command
    # docker stop -java-app

In the same way, as stated above, we can help you with Dockerizing your enterprise applications and make it easy to deploy and run them without any hassle.

At Loves Cloud, we are constantly leveraging the power of various open source software solutions to automate, optimize, and scale the workloads of our customers. To learn more about our services aimed at the digital transformation of your business, check