1,100 views

Here comes the most awaited feature of 2017 – “Building Docker Swarm cluster which includes all Windows cluster, or a hybrid cluster of Linux and Windows machines, or all Linux systems”.  With the inclusion of the recent Docker 17.03 overlay networking feature for Windows Server 2016, it’s now possible to create swarm clusters that include both Windows and Linux environment across the both public and private cloud infrastructure.

Today most of the enterprises manage a diverse set of applications or workloads that might includes both traditional applications & microservices, built on either or both of Linux and Windows platform. Docker now provides a way to modernize all these different applications by packaging them in a standard format which does not require software development teams to change their code. Organizations can containerize traditional apps and microservices and deploy them in the same cluster, which includes both Linux & Windows environment.

Building Hybrid Docker Swarm Mode Cluster Environment

Under this blog post, I will showcase how to build the hybrid Docker Swarm Mode cluster. I will be leveraging Google Cloud Platform where I have 2 Windows Server 2016 & 1 Ubuntu 16.04 instance up and running.

Setting up Windows Server 2016 with Docker 17.03 Enterprise Editio

  • Bring up Windows Server 2016 instance on Google Cloud Platform 
  • Setup Windows password using the below command and then proceed to download the RDP file

[simterm]

$gcloud beta compute –project “psychic-cascade-175904” reset-windows-password “windows2016” –zone “asia-east1-a”

ip_address: 35.194.X.X

password: XXXXXXX

username: <yourusername>

[/simterm]

  • Open up the RDP file downloaded under step-2 and connect to the instance remotely.
  • Just 3 commands and docker should be up and running on Windows Server 2016

[simterm]

  • Install-Module -Name DockerMsftProvider -Force
  • Install-Package -Name docker -ProviderName DockerMsftProvider -Force
  • Restart-Computer -Force

[/simterm]

 

This should restart the Windows instance and you should be able to see Docker up and running once it comes back.

One can easily verify if Docker 17.03.2 EE  is up and running using the below command:

 

Configuring Windows Server 2016 as Docker Swarm Manager Node:

Run the below command to make this node as a Swarm master node:

[simterm]

docker swarm init –listen-addr 10.140.0.2:2377 –advertise-addr 10.140.0.2

[/simterm]

 

Listing the Swarm Mode cluster nodes:

As of now, there is only 1 manager node which gets listed.

Joining Windows Server 2016 as the first Worker Node

Install Docker 17.03 EE on the 2nd Windows Server 2016 instance and issue the below command to join it as worker node:

 [simterm]

docker swarm join –token SWMTKN-1-4ia5wbutzfoimx5xm7eujadpa6vuivksmgijk4dm56ppw5u3ib-6hvdrvee3vlnlg8oftnnj80dw 10.140.0.2:2377

[/simterm]

 

Listing out the Swarm Mode cluster:

 

Adding Linux System to the Cluster

Login to Ubuntu 16.04 instance, install Docker 17.06  and then issue the below command to join it as 3rd node to the existing cluster:

[simterm]

worker@ubuntu1604:~$ sudo docker swarm join –token SWMTKN-1-4ia5wbutzfoimx5xm7eujadpa6vuivksmgijk4dm56ppw5u3ib-6hvdrvee3vlnlg8oftnnj80dw 10.140.0.2:2377

This node joined a swarm as a worker.

[/simterm]

Wow ! This builds up our first hybrid Swarm Mode cluster which includes 2 Windows nodes & 1 Linux Nodes.

A Quick way of verifying the OS type:

 

Create an Overlay Network For Swarm Cluster

Before we start deploying application, we need to create an overlay network which spans across the cluster nodes. By default, it shows up the below listed network drivers:

As shown above, it displays 3 different networks – nat, none and ingress. Let us create a new overlay network ‘collabnet’ using the below command:

[simterm]

docker network create -d overlay collabnet

[/simterm]

 

Creating our First Windows-based Service container

It’s time to create our first service. I will pick up MSSQL container which will use ‘collabnet’ overlay network and should get deployed only on Windows platform based on applied constraint as shown below:

[simterm]

docker service create \

–network collabnet –endpoint-mode dnsrr \

–constraint ‘node.platform.os == windows’ \

–env ACCEPT_EULA=Y \

–env-file db-credentials.env \

–name db \

microsoft/mssql-server-windows

[/simterm]

 

Ensure that you have db-credentials.env under the same directory with the below content:

[simterm]

sa_password=collabnix123
SA_PASSWORD=collabnix123
DB_CONNECTION_STRING=Server=db;Database=SignUp;User Id=sa;Password=collabnix123

[/simterm] 

Once you create service, you can verify it up and running with the below command:

[simterm]

docker service ps db

[/simterm]

Scaling the DB service 

Let us scale the DB service and see if it still applies only to Windows Platform:

As shown above, there are now 3 instance of the same application up and running. The MS SQL is now running on only Windows system based on the constraint specified.

Creating Linux specific applications 

Let us create a Web application having frontend as WordPress and backend as MySQL container with a constraint that it should get deployed only on Linux specific platform.

[simterm]

docker service create \

–replicas 1 \

–name wordpressdb1 \

–network collabnet \

–constraint ‘node.platform.os == linux’ \

–env MYSQL_ROOT_PASSWORD=collab123 \

–env MYSQL_DATABASE=wordpress

mysql:latest

[/simterm]

[simterm]

docker service create \

–env WORDPRESS_DB_HOST=wordpressdb1 \

–env WORDPRESS_DB_PASSWORD=collab123 \

–network collabnet –constraint ‘node.platform.os == linux’ \

–replicas 4 \

–name wordpressapp \

–publish 80:80/tcp \

wordpress:latest

[/simterm]

 

Hence, we saw that MS SQL service is running on Windows host instance while WordPress application specific to Linux is successfully up and running on Linux nodes which proves that the newer Swarm Mode comes with an ability to intelligently orchestrate across mixed clusters of Windows & Linux worker nodes.

Adding Linux Worker Node and promoting to Manager

You should be able to view the list of nodes from Ubuntu manager node too:

In case you are looking out for application which uses frontend application running on Windows platform whereas the backend application uses Linux, here is a quick example.

Did you find this blog helpful?  Feel free to share your experience. Get in touch @ajeetsraina

If you are looking out for contribution/discussion, join me at Docker Community Slack Channel.

Clap

Categories: Docker

Ajeet Raina

My name is Ajeet Singh Raina and I am an author of this blogging site. I am a Docker Captain, ARM Innovator & Docker Bangalore Community Leader. I bagged 2 special awards last year(2019) : Firstly, “The Tip of Captain’s Hat Award” at Dockercon 2019, San Francisco and secondly, “2019 Docker Community Award“. I run Collabnix Community Slack with over 4700+ audience as well as Redis Community Slack with close to 500+ members. I have built popular GITHUB repositories like DockerLabs, KubeLabs, Kubetools, RedisPlanet Terraform etc. with the support of Collabnix Community. Currently working as Developer Relations Manager at Redis Labs where I help customers and community members adopt Redis. With over 11,000+ followers over LinkedIn & close to 4800+ twitter followers, I like sharing Docker and Kubernetes related content . You can follow me on Twitter(@ajeetsraina) & GitHub(@ajeetraina)

3 Comments

Fraser Goffin · 21st August 2017 at 1:31 pm

What about a service that utilises containers hosted on a mix of Windows and Linux over the same overlay network, can you show an example of that ?

    Ajeet Singh Raina · 21st August 2017 at 2:15 pm

    Yes, it is possible today. Here is the snippet of docker-compose.yml for WordPress where your frontend application runs on Linux while backend runs on Windows over the same overlay network:

    version: “3.3”
    services:

    backend:
    image: nanoserver/mysql
    environment:
    MYSQL_USER: root
    MYSQL_PASSWORD: Password123
    ports:
    – mode: host
    target: 3306
    published: 3306
    networks:
    – collabnet
    deploy:
    endpoint_mode: dnsrr
    placement:
    constraints:
    – ‘node.platform.os == windows’

    frontend:
    depends_on:
    – backend
    image: wordpress:latest
    environment:
    WORDPRESS_DB_HOST: backend:3306
    WORDPRESS_DB_USER: root
    WORDPRESS_DB_PASSWORD: Password123
    ports:
    – mode: host
    target: 80
    published: 80
    networks:
    – collabnet
    deploy:
    endpoint_mode: dnsrr
    placement:
    constraints:
    – ‘node.platform.os == linux’

    networks:
    collabnet:

    All you need is :

    $docker stack deploy -c docker-compose.yml myapp

    and it should be able to schedule the container on the right OS systems.

    If you want to try, pull this from https://raw.githubusercontent.com/ajeetraina/docker101/master/play-with-docker/wordpress/windows/docker-stack.yml.

Leave a Reply to Ajeet Singh Raina Cancel reply

Your e-mail address will not be published. Required fields are marked *