September 20, 2019

Tools to Micro-service (Part 2 : Docker)

Tools to Micro-service (Part 2 : Docker)

So you split your code base between multiple multiple services. Each team took the responsibility of one module and all been working very hard. Now It's time to deploy to production server. And hold and behold team A been working with the newest version of Python, node or whatever and the rest of you code base doesn't or has not been tested on this version. Or service B require a program that for some reason only available for on Ubuntu and you must compile it to run on your current distro and maybe Service C and Service D both require this program to exist but each require a different version. These problem are well too common and such a hassle to solve.

Well docker comes to the rescue. Docker is a containerization solution that allow you to ship your service with all of its dependencies and run time environment together. Developers are usually bad with tracking dependencies outside of your code base and they are especially bad with tracking the steps of installing a certain program if there are special steps to take.

Docker create containers by executing a dockerfile Which looks something like this:

FROM node #Dockerhub provides ready to use images
WORKDIR /app #creating a folder to host the code
COPY package.json . #copy your dependencies
RUN npm install # install dependecies
COPy . . #Copy the rest of the project to the container
ENTRYPOINT [''] #how to run the container
  • You only need to specify your running environment once and each consecutive time you just deploy your ready to use containers with all the software already installed
  • You no longer need to separately install all the tools you need in each machine you use. Every lives inside a container and is shipped together with your code base.
  • Each developer has to be specific and explicit with the dependencies he uses  
  • You no longer have the excuse "Well .. It runs on my machine"
  • For some libraries you mean need to take extra steps to make them run and a Dockerfile is a great way to document these steps.