0

I've engineering background mostly with coding/dev't than deployment. We have introduced Microservices recently to our team and I am doing POC on deploying these Microservices to Docker. I made a simple application with maven, Java 8 (not OpenJdk) and jar file is ready to be deployed but I stuck with the exact steps on how to deploy and run/test the application on Docker container.

I've already downloaded Docker on mac and went over this documentation but I feel like there are some steps missing in the middle and I got confused.

I appericiate your help.

Thank you!

WowBow
  • 7,137
  • 17
  • 65
  • 103

1 Answers1

1

If you already have a built JAR file, the quickest way to try it out in docker is to create a Dockerfile which uses the official OpenJDK base image, copies in your JAR and configures Docker to run it when the container starts:

FROM openjdk:7
COPY my.jar /my.jar
CMD ["java", "-jar", "/my.jar"]

With that Dockerfile in the same location as your JAR file run:

docker build -t my-app .

Which will create the image, and then to run the app in a container:

docker run my-app

If you want to integrate Docker in your build pipeline, so the output of each build is a new image, then you can either compile the app inside the image (as in Mark O'Connor's comment above; or build the JAR outside of the image and just use Docker to package it, like in the simple example above.

The advantage of the second approach is a smaller image which just has the app without the source code. The advantage of the first is you can build your image on any machine with Docker - you don't need Java installed to build it.

Community
  • 1
  • 1
Elton Stoneman
  • 17,906
  • 5
  • 47
  • 44
  • I am trying to understand what happens after you run the app ? Does it mean it is running inside docker's operating system ? – WowBow Oct 07 '16 at 23:48