Dockerizing WSO2 hospital service from source

In this blog post, we are going to build the hospital service backend jar used in WSO2 Enterprise Integrator samples from the source and bundle it inside a Docker container. Sources for this project are available in this GitHub repo.

Steps to create, run and test the hospital service docker container

  1. Clone the GitHub repo to the local machine.

  2. Open a Powershell window and navigate to the folder where the cloned project is located.

  3. Execute “docker build -t hospitalserviceagent:v2 .” to create the Docker image.

  4. Execute “docker run -p 9090:8080 hospitalserviceagent:v2” to run a container based on the created image.

  5. Navigate to http://localhost:9090/healthcare/surgery in a browser window and you should see an output as in step 5 in Sending requests to the ESB.


Explanation 

This Docker file used two docker images in a two-step process to build this final Docker image.  The first step is the build stage which uses the maven:3-openjdk-8 image as the build image. This image has an openjdk and maven installed to build the executable jar from the source. In the next three lines, we create a new folder in the base image, copy the source files into the new folder and set the working directory to be the newly created folder. Then we execute the maven package command to create the executable jar in the target directory.


The second step of this Dockerizing process uses the openjdk:8-jre-slim image as the base image. Our objective for this image is to copy the executable jar created in the above build image, expose the port where the service is going to run and run the executable jar in the next image. This is exactly what the last five statements do in the Dockerfile.


When running the container in above step 4, we have mapped the container’s exposed port 8080, to our localhost port 9090 so that we can access it to verify the service’s operation. Note that we can map the container’s exposed port 9090 onto any available port of the host machine.  

Extensions

Even though this blog post explains how to build and run this locally, and can be uploaded to a container registry and then deployed in a Kubernetes cluster, this whole process involves a lot of manual steps that can be simplified using a DevOps Solution.


Comments

Popular posts from this blog

Running a Docker build agent on Azure Kubernetes Service (AKS)

Azure DevOps Docker DotNet Build Agent

Building Azure DevOps pipelines with a Docker agent