/docker-continuous-deployment

continuous deployment of a microservices application with Docker

Primary LanguageJavaScriptMIT LicenseMIT

Continuous Deployment with Docker

Description

This project shows a web application built using a microservices architecture.

There are two microservices:

  • rest-count implemented in Python (Flask microframework) using a Redis database
  • rest-ip implemented in Node.js (Express framework) using a MongoDB database

Using consul-template you can generate a dynamic Nginx configuration so that you can deploy new microservices version with no downtime.

You can find additional information on my Slideshare presentation "Always be shipping"

Diagram

Prerequisites

Docker 1.11

docker-compose 1.7

Getting started

Run the following commands in terminal (the first time you have to wait for a few minutes to download the Docker base images):

docker-compose -f application/docker-compose.yml up -d

open your browser to http://localhost:8080/

you can check the Consul state on http://localhost:8500/ui/

now edit rest-count/main.py (for example, you can increase the version to 1.1)

docker build -t francescou/rest-count rest-count/

docker-compose -f application/docker-compose.yml up -d restcountprimary

sleep 15

docker-compose -f application/docker-compose.yml up -d restcountbackup

the updated microservice will be deployed with no downtime.

You can also modify the rest-ip microservice in the same way (see rest-ip/app.js).

Scaling microservices

this section will explain how to can scale up and down docker-compose services.

open your browser to http://localhost:8500/ui/. There you will find a rest-count service, running on two nodes (one primary and one backup). Note that each node is a Docker container. Execute

docker-compose -f application/docker-compose.yml scale restcountprimary=3

check again http://localhost:8500/ui to ensure that there are now four rest-count instance (three primary and one backup).

Make a few requests to http://localhost:8080/api/v1/count and then run docker-compose -f application/docker-compose.yml logs to see how requests are processed by different rest-count instances.

You can now scale down the rest-count service without having any down time, e.g.:

docker-compose -f application/docker-compose.yml scale restcountprimary=2

Again, you can check http://localhost:8500/ui to see that there are now only two primary instances.