Goglides Dev 🌱

devbinod
devbinod

Posted on • Updated on

Deploy Simple Java Application with docker

Here I am going to create a simple java application that prints the message in console and run it by using docker container.

Step 1: Create a directory dockerize-java-application and goto inside that directory.
mkdir dockerize-java-application && cd dockerize-java-application

Step 2: Create a simple java application having name HelloWorld.java.

class HelloWorld {

    public static void main(String[] args) {

        System.out.println("Running java application inside docker container");
    }

}
Enter fullscreen mode Exit fullscreen mode

Step 3: Create a Dockerfile.

FROM openjdk:7u111-jdk
MAINTAINER BINOD PANT
WORKDIR /app
COPY . .
RUN javac HelloWorld.java
CMD ["java", "HelloWorld"]
Enter fullscreen mode Exit fullscreen mode

Step 4: Build docker image using following command.
docker build . -t pantbinod/java-helloworld:v1

Step 5: Finally run built docker image using following command.
docker run pantbinod/java-helloworld:v1

After running this command we will see following output.

Running java application inside docker container

Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
bkpandey profile image
Balkrishna Pandey

I wonder if we can show the use case of multistage Dockerfile as well. Good writeup :)