#docker swarm

Install Docker and Docker Swarm on CentOS7

This tutorial will show you how to install Docker and Docker Swarm on CentOS7. This tutorial is for Docker Version 1.11 and I use Vagrant and VirtualBox to create CentOS 7 in Virtual Machine.

Stop worrying about what you have to loose and start focusing on what you have to gain

Stop worrying about what you have to loose and start focusing on what you have to gain

Create a Vagrantfile for CentOS7

Turn on your Virtual Machine with command:

After finishing creating CentOS server, you access the server via SSH by command:


Go to root account:

In the next step, we will install Docker Engine following the official tutorial of Docker.

Add Docker Repository  into CentOS

Running the installation

Start Docker Service

Enable Docker run on OS Start

Docker Swarm

Installing Docker Swarm via Docker Pull

Open Docker Service Configuration file

In the line contains ExecStart, we add text as below

And now, reload Docker Service

Now we can run Swarm Node

And running Swarm Manage

Finally, verify your work


Thanks for your reading!!!

Microservice with Docker Swarm and Consul – Part 2

In the previous part, I showed you step by step install Node Gateway and Node Agent-One. In this post, we will continue to install Node Agent-Two. After finishing this step, you will understand how to scale or replicate you service in Docker Swarm, and how to Nginx load-balance your services with Consul and Consul-Template.

Nginx Load-balancer, Docker Swarm Cluster

Nginx Load-balancer, Docker Swarm Cluster

Node Agent-Two

In this node, we also need to install Consul and Swarm. Similar with the last post,  we run Consul with command:

And run Registrator:

Restart Docker Daemon:

And run Swarm node to join Swarm Cluster:

Now, the node is ready for running you microservices:

After command above, you are scale your services from one container to two containers running in Docker Swarm

You can check with consul members command:


To scale your service (in my case is angular-admin-seed service), you should access either Node Agent-One or Agent-Two with root privilege, and type commands:

And check with docker ps command, the output should be:

And check /etc/nginx/sites-available/default at node API Gateway:

It means that Nginx is loading balance between three running services.


After reading, the series of post, we know that there are many open sources support us implement Microservices. However, we can not own a microservices system with one step at this time. We need to deeply understand about tools, open source and Linux as well to implement it.

Microservices with Docker Swarm and Consul

Recently, perhaps you hear too much about Microservices includes the concepts, cons, pros … I sure that you will ask yourself that how to implement it for your project? It is not easy to answer your question. In this post, i will tell you a part of my story after six month implement a social network project.

The story I would like to tell you is how to deploy a microservices with Docker Swarm and Consul  (step by step instruction). With , my scenario, I have three nodes, installed Ubuntu 14.04 with 2G Ram and 2 CPUs. I used Vagrant and Virtualbox to build it.

Microservice with Docker Swarm and Consul

Microservice with Docker Swarm and Consul

As the image above, We will install Consul in all nodes. With, Node Gateway, It is installed Nginx to load-balance and used as a API Gateway for your services. And we also install Consul-Template to help you change Nginx configuration once there is an new service is on or down via Consul.

With Node Agent-One and Node Agent Two, we will use it as Swarm Clusters. So we will install Swarm, and run Swarm Join for all of them. Beside that, we have to install Consul and Registrator. Consul is a Service Discovery, and Registrator will help you announce for Consul know if there is any service is up or down.

There are many steps we need to do to build this system. So I deviced my post to three parts:

I also publish all scripts to build this system to Github. You can check out it microservices-swarm-consul

So you just can download it and run:

Note: Make sure you installed Virtualbox and Vagrant in your machine. And if there is any issue in my code. Please report me. Thank you


Before you reading my series of the posts, you should read about the concept of the tools we will use for deploy microservices

Docker & Docker Swarm

Docker is a platform for developers and sysadmins to develop, ship, and run applications. Docker lets you quickly assemble applications from components and eliminates the friction that can come when shipping code. Docker lets you get your code tested and deployed into production as fast as possible.

Docker Swarm is native clustering for Docker. It allows you create and access to a pool of Docker hosts using the full suite of Docker tools. Because Docker Swarm serves the standard Docker API, any tool that already communicates with a Docker daemon can use Swarm to transparently scale to multiple hosts


  • Service Discovery
  • Key/Value Storage
  • Failure Detection
  • Multiple Datacenter


  • Listen/Query the updates from Consul
  • Updates Configuration File by the templates provided
  • Executes commands


Registrator automatically registers and deregisters services for any Docker container by inspecting containers as they come online. Registrator supports pluggable service registries, which currently includes Consul, etcd and SkyDNS 2.

In next step, please go to Install Load Balance, API Gateway and Docker Swarm