As part of our MedRec API playpen initiative we had already developed some REST API’s using Node.js and leveraged MongoDB running on Oracle IaaS as the persistence layer. . This post describes what I did to dockerise the MedRec API application and eventually run it on the Oracle Container Cloud Service (OCCS).
The APIs have already been made available for interested parties to interact with via SwaggerUI. Of course developers could develop their own code (or any REST client) to interact with them. As a team we used a combination of the Oracle Developer Cloud Service (Git repository, Issue Tracker, Build Server etc) and also the public GitHub to provide public access to our project code. As the source code for the Node.js project containing the API’s was pushed to GitHub I simply did a clone of the Node application code in order to download and run it locally (MedRec API tutorials available here).
The application ran well enough on my local laptop which running Ubuntu 16.04, however I really wanted to be able to try to run the app and MongoDB as a Docker image/stack on my laptop. After I had the application successfully “Dockerised”, then I planned to deploy my application stack to the Oracle Container Cloud Service. I also wanted to explore the use of the GitHub / Docker Hub integration to build my image on Docker Hub, and then from within the Oracle Container Cloud Service (OCCS). With the application image available on Docker Hub, I could then pull my image from that source in order to run it up on OCCS.
A good blog can really help bring you up to speed quickly and help overcome inertia to get you started and I would like to acknowledge the help that Mauricio Payetta’s blog provided me.
In this series of blog posts I plan to retrace what I did during my self-learning.
In order to break it up into bite sized chunks, I decided to use the following outline;
Part 1 – Dockerise the MedRec APIs
- Use git to clone the application project repository
- Source a suitable Docker base image for the project
- Add an empty Dockerfile to the project, and then add steps into the Dockerfile to Install Nodejs, Node Package Manager (npm), application code and then validate that the Dockerfile builds successfully.
- Build and run the Docker image to validate that the image is functional
Part 2 – Add MongoDB layer using Docker-Compose
- Add a docker-compose.yml file to the project, which allows me to define a stack (essentially a container for the node app and another container for MongoDB)
- Build and run using Docker-Compose
- Add occs-stack.yml file, which allows me to deploy the docker image containing my app, and MongoDB to OCCS as a single deployment.
Part 3 – Trigger a Build of the MedRec API Docker Image
- Link Docker Hub and Git Hub accounts
- Set up Docker Hub to build based on changes to the Master Branch of the git repository
- Using Git, add new/updated files (eg Dockerfile), commit, and push the project to public Git Hub
- Confirm that the docker image was built by viewing Docker Hub
Part 4 – Deploy the Stack on OCCS
- Create a new stack in Oracle Container Cloud Service (OCCS) that references the Docker Hub repository / image
- Deploy the stack to OCCS managed container and test connectivity and application functionality
In terms of my starting point, I already had Docker, Docker-Compose and GIT client installed prior to trying this out. If you need to install Docker best to check out the official product documentation for your operating system on the Docker site. I installed docker-compose following the official instructions from Docker Hub. The diagram below attempts to show my planned journey.
Look for the next installment – Dockerise the MedRec APIs.