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.
- Follow the instructions in WSO2 MSF4J readme and create your microservice project. Then generate the executable jar file.
- Copy this jar file into your hosting machine.
- Install Docker in your hosting machine.
- I'm using a Linux (Ubuntu) environment for this example.
- https://askubuntu.com/questions/938700/how-do-i-install-docker-on-ubuntu-16-04-lts
- Now create a Dockerfile next to your jar file.
- Enter the following lines into your Dockerfile.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM airdock/oracle-jdk:1.8 | |
COPY Hello-Service-0.1-SNAPSHOT.jar /tmp/helloService.jar | |
EXPOSE 8080 | |
CMD ["java","-jar","/tmp/helloService.jar"] |
- 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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
- Now go to your web browser and access the service via port 8080.
Happy coding!!
No comments:
Post a Comment