Thursday, November 2, 2017

How to run MSF4J service in Docker

In order to create your microservice project you need to have Maven and JDK installed on your developer machine. Then once you get the executable jar of the MSF4J project you can run this in any of the Docker hosting machines. For the hosting environment, you only need to have Docker installed on the hosting machine. 

  • Enter the following lines into your Dockerfile.
FROM airdock/oracle-jdk:1.8
COPY Hello-Service-0.1-SNAPSHOT.jar /tmp/helloService.jar
EXPOSE 8080
CMD ["java","-jar","/tmp/helloService.jar"]
view raw Dockerfile hosted with ❤ by GitHub
    • This will grab an existing docker image which will create the JDK runtime environment to run the jar file. 
    • Then the script copies the jar file into /tmp directory.
    • Next, it exposes port 8080 to run the service.
    • Finally, it runs the jar file
  • Execute the following commands in terminal to run the Dockerfile.
# Below command will build the Dockerfile in the current directory and create image
# -t option will give a name to the image for identification
docker build -t hello-image .
# Bellow command will create the container from the image and start the service
# -p option will map the docker container port 8080 service with host machine port 8080
# --name option give a name to the container for identification
docker run -p 8080:8080 --name hello hello-image
view raw bash.sh hosted with ❤ by GitHub
Happy coding!! 

No comments:

Post a Comment