Today we are going to show how to setup Docker for Windows and two Ubuntu virtual machines on a Windows 10 desktop to create a cluster where we can define services and schedule them to run. Docker 1.12 introduced a few new features which are very exciting. First, Docker for Windows utilizes a Hyper-V Linux virtual machine to host a Docker installation. The Docker and Microsoft teams have integrated this into Windows 10 to the point t hat one can run Docker services directly from the PowerShell or standard Windows command line.
Docker 1.12 is also the first release with a native Swarm option built-in. With the Docker Swarm mode in version 1.12 one can create Swarm clusters for managing services across virtual machines and bare metal nodes directly from the base Docker Engine installation. If you were thinking of setting up a Raspberry Pi docker cluster (check Hypriot for this), you can instead use a Hyper-V virtual environment on an Intel NUC, notebook PC or a standard desktop PC and have a faster/ cheaper 0-5 node “cluster” with more RAM.
Here are the pre-installation steps we did:
- Install Docker for Windows on our base system. Here is the guide you need. This is as simple as running the executable and restarting the PC if you did not have Hyper-V installed. The Docker for Windows installer will guide you through this. If you do have issues with Hyper-V installation, there is a BIOS setting to enable Intel VT-x virtualization (or equivalent on other architectures) which you should ensure is enabled. This should take 2-5 minutes.
- Ensure you have proper RAM/ CPU allocations for Docker for Windows and for the two Ubuntu VMs. This should take you 1 minute to complete.
- Setup two Ubuntu 16.04 LTS Hyper-V VMs. We used our standard base server installation with OpenSSH server also installed just to make this process easy. There are many other OSes available but Ubuntu works relatively well in Hyper-V so that is what we are using. Even installing from an ISO this will take no more than 5-10 minutes.
- Install Docker 1.12 on the Ubuntu VMs (guide here.) Which should take around 2 minutes.
- Connect to the Ubuntu VMs (we are using OpenSSH and Putty) and a Windows command prompt or Windows Power Shell. This should take about 1 minute.
With a bit of multi-tasking, you should be able to get the above complete in around 10 minutes. It will be a bit faster if you are a Hyper-V guru with pre-made templates and could take a few minutes longer if you are completely new to Hyper-V.
We made a short video using the above demonstration to show how easy the new Docker Swarm mode is. Creating a cluster takes seconds and Docker handles bits like encryption.
As you can see in the 144 second video we initialized a three node Docker Swarm cluster. We defined a simple service and then verified that the service was scheduled and running on two of the three cluster nodes. Using many traditional clustering solutions, this would have taken hours of setup time. Docker for Windows and Docker 1.12 are game changing in how easy they are to get running.
If you were to spend a nominal amount of additional time, and had sufficient RAM, you could easily scale the Swarm cluster out to 8-16 nodes by adding more Ubuntu VMs. Working in a virtual world is great, however the next step is moving this proof of concept into something usable: a bare metal cluster sitting in one of our data centers.