Communicate Multiple VM (OS - Ubuntu) On Windows10 Using Docker Swarm

Introduction

The purpose is to communicate Multiple VM with the same application hosted on all of them and act as load balancer using Docker swarm.

We will be creating two VM (OS- Ubuntu) inside Windows 10 and will communicate by deploying application in both VM. There will be one Master node, 1 worker node using Docker Swarm, and for this, we will be using Virtual BOX.

The below link explains the steps for virtual box setup.

https://www.c-sharpcorner.com/article/how-to-install-ubuntu-on-windows-10-using-virtualbox/

NOTE
Don’t get confused with VM Name because I have reinstalled Ubuntu many times with different host Name, base line assume it as two machines as VM1, VM2 that’s it.

Problem

Before jumping into link, what you keep in mind is that:

  1. Both VM should have different IP addresses, else when you create VM they will have same IP, and it will trouble you while communicating.
  2. Check Network – it should be BRIDGED

As shown below 2 VM (Docker_Host_VM1, Docker_Host_VM2 both have same IP)

Communicate Multiple VM (os - Ubuntu) on Windows10 using Docker Swarm

You can give different IP address to VM by following this https://www.youtube.com/watch?v=gqcVjn13PCE, and then check Ubuntu > Settings here:

Communicate Multiple VM (os - Ubuntu) on Windows10 using Docker Swarm

System Requirement to set up

STEPS

Step 1

After Virtual box set up is configured you can see 2 Ubuntu VM as shown below:

Communicate Multiple VM (os - Ubuntu) on Windows10 using Docker Swarm

Step 2

Run following commands one by one sequentially, for docker installation and required tools in use inside Ubuntu terminal.

  • apt-get install -y openssh-server
  • apt-get install -y curl
  • apt-get install -y vim
  • apt-get update
  • systemctl enable ssh
  • systemctl start ssh
  • sudo apt install net-tools

Visually it should look like this:

Communicate Multiple VM (os - Ubuntu) on Windows10 using Docker Swarm

Communicate Multiple VM (os - Ubuntu) on Windows10 using Docker Swarm

Communicate Multiple VM (os - Ubuntu) on Windows10 using Docker Swarm

Communicate Multiple VM (os - Ubuntu) on Windows10 using Docker Swarm

Step 3

Uninstall Older versions of Docker were called docker, docker.io, or docker-engine.

If these are installed, uninstall them:

$ sudo apt-get remove docker docker-engine docker.io containerd runc

Step 4

Install Docker Engine using the convenience script

  • $ curl -fsSL https://get.docker.com -o get-docker.sh
  • $ sudo sh get-docker.sh

Communicate Multiple VM (os - Ubuntu) on Windows10 using Docker Swarm

Step 5

Once all the above done, Verify Docker is installed

sudo docker –version

Communicate Multiple VM (os - Ubuntu) on Windows10 using Docker Swarm

Step 6

Now try to ping both machines with each other using their IP address, in Ubuntu you use to check IP from CMD line,

Ifconfig

Communicate Multiple VM (os - Ubuntu) on Windows10 using Docker Swarm

Communicate Multiple VM (os - Ubuntu) on Windows10 using Docker Swarm 

Also, ping with Original host (windows) is also able to ping these 2 VM and vice versa

Communicate Multiple VM (os - Ubuntu) on Windows10 using Docker Swarm

Step 7

Now we will create Swarm using these two VM’s via Docker command.

  • To Master + worker Node

$> sudo docker swarm init

Here VM-2 is Master/Leader Node (after Enter you get token)

VM-1 is worker node, (we copy paste same token and execute in VM-1)

Now run below command this show all Swarm Node in conjuction (Leader Node with ‘*’ sign, Worker Node)

$> sudo docker node ls

Communicate Multiple VM (os - Ubuntu) on Windows10 using Docker Swarm

Step 8

In the next part, we will be hosting application to both VM’s, and it will be accessible by Windows OS, OR using Curl in VM.

So, that’s how we can create Multiple VM (OS-Ubuntu here) inside Windows10-OS via Virtual Box. In addition, we can communicate and host our application via docker concept.

Happy Dev ops!! Let me know if you have any questions about above part.