In my last article, about Windows Containers, I’ve shown you how to configure a Swarm Cluster made out of two Container Hosts.
Today, I’ll show how to create Containers on a Swarm Cluster which is a bit different than deploying them on a Windows Container host.
Once we move to a Swarm Cluster the terminology of containers is changing from Deploying Containers to Services.
In swarm mode, Containers are Services and a service is a container.
Get Started
To create the most basic Service on a swarm Container I’ll use the command below:
docker service create microsoft/nanoserver-insider
We can easily create multiple services in the same way we create containers on a Container host.
To view all running services on a swarm cluster I’ll run the cmdlet
docker service list
To create a more advanced service with the networking configured and load balancing I’ll use:
docker service create --name webapp -endpoint-mode=dnsrr --network=swarmnet microsoft/nanoserver-insider
Monitor
To monitor my services I’ll use the command below.
Docker service ls
Scale-up
With Swarm, we can easily scale up our application using a the command below which will create 4 containers across the cluster
Docker service scale webapp=4
docker service ps webapp
Load Balancing
Docker swarm gives the option to load balance a service using DNS Round Robin using the parameter below:
-endpoint-mode=dnsrr --network=swarmnet
Note: We can also use External load balancer using published ports, If you are using External Load Balancer we need to use the Publish switch and expose the endpoints
Conclusion
Creating Services on a Windows Containers Swarm Cluster is similar deploying containers a docker host.
Once you get used to the new commands, everything is the same and easier because we have the option to load balanced the containers and protect them using HA.