September 21, 2019

Tools to Micro-service (Part 3 : Docker-Compose)

Tools to Micro-service (Part 3 : Docker-Compose)

So by now you created your many containers, all built and all ready to be started. Now all you have to do is one by one, give them a representative name, create whatever volumes/network/secret/environment variable they require  and create your many containers and don't forget to remember these configurations because you  might need to do it all over again on the next system update.

But wait there is a simpler solution. Docker-compose is a wrapper around the docker command allowing you to manage multiple containers in a transparent manner within a context of a project.

A sample configuration file may look like

version: '3'
    build: .
    - "5000:5000"
    - .:/code
    - logvolume01:/var/log
    - redis
    image: redis
  logvolume01: {}

Our sample project is composed of web Service, that gonna be created from our source files and a Redis database that gonna be conveniently downloaded from the net. Both these services and optionally many more represent our project. We can neatly specify everything project related withing our docker-compose.yml file.

Starting our project can be through the command

docker-compose up -d

Docker-compose have an other utility. While creating our containers, it will create DNS records that conveniently reference the service's name to the containers (because it can be many containers for a single service) IP address. Meaning that within your code you can query a service by its name and this solves the problem of Service Discovery that can popup in a mico-service architecture.