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:

Scale

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.

Conclusions

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.