Container Orchestration with Docker Swarm

Container Orchestration with Docker Swarm

Containers eat the DevOps world. Docker is leading the pack with the ubiquitous Docker engine runtime and a plethora of related tools. In this article, I provided some basic information about Docker. A single container is, however, not very useful. Even a collection of containers on the same machine has limited utility. The power of containers shines brightest when you build large systems made up of many machines running lots of interacting containers. Orchestrating all these containers is a difficult problem. Kubernetes and Mesos, as well as most cloud platforms, provide solutions. But Docker, as a company, wants in on the orchestration cake too. That’s were Docker Swarm comes in. It is arguably the simplest orchestration solution for Docker containers and it is built into the Docker engine itself.

I assume you have installed Docker on your machine. To create a local cluster called “swarm-cluster” run the following command:

> docker-machine create -d virtualbox swarm-clusterRunning pre-create checks...(swarm-cluster) No default Boot2Docker ISO found locally, downloading the latest release...(swarm-cluster) Latest release for github.com/boot2docker/boot2docker is v1.12.3(swarm-cluster) Downloading C:Users	he_g.dockermachinecacheoot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v1.12.3/boot2docker.iso...(swarm-cluster) 0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%Creating machine...(swarm-cluster) Copying C:Users	he_g.dockermachinecacheoot2docker.iso to C:Users	he_g.dockermachinemachinesswarm-clusteroot2docker.iso...(swarm-cluster) Creating VirtualBox VM...(swarm-cluster) Creating SSH key...(swarm-cluster) Starting the VM...(swarm-cluster) Check network to re-create if needed...(swarm-cluster) Waiting for an IP...Waiting for machine to be running, this may take a few minutes...Detecting operating system of created instance...Waiting for SSH to be available...Detecting the provisioner...Provisioning with boot2docker...Copying certs to the local machine directory...Copying certs to the remote machine...Setting Docker configuration on the remote daemon...Checking connection to Docker...Docker is up and running!To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: C:Program FilesDockerDockerResourcesindocker-machine.exe env swarm-cluster

Now, you need to load the configuration into your shell.

On Windows:

& "C:Program FilesDockerDockerResourcesindocker-machine.exe" env swarm-cluster | Invoke-Expression

On Mac/Linux:

 eval "$(docker-machine env local)"

Generating a Discovery Token

The next step is generating a discovery token. The containers that participate in the cluster need to be able to discover each other.

You do this by running the “swarm” image from the Docker registry.

> docker run swarm createUnable to find image 'swarm:latest' locallylatest: Pulling from library/swarm220609e0bc51: Pull completeb54bf338fe2f: Pull completed53aac5750d5: Pull completeDigest: sha256:c9e1b4d4e399946c0542accf30f9a73500d6b0b075e152ed1c792214d3509d70Status: Downloaded newer image for swarm:lateste18fe8919e3c504e7f00284879fa9933

The last line is our token: e18fe8919e3c504e7f00284879fa9933. This discovery token is provided by Docker’s hosted discovery service. You may use other discovery back ends such as etcd, consul or zoo keeper.

Now, armed with this token we can add start building out cluster. First, we need a master. The master is responsible for scheduling containers to run on the cluster nodes (AKA agents).

> docker-machine create           -d virtualbox           --swarm           --swarm-master           --swarm-discovery token://e18fe8919e3c504e7f00284879fa9933           swarm-master          Running pre-create checks...Creating machine...(swarm-master) Copying C:Users	he_g.dockermachinecacheoot2docker.iso to C:Users	he_g.dockermachinemachinesswarm-masteroot2docker.iso...(swarm-master) Creating VirtualBox VM...(swarm-master) Creating SSH key...(swarm-master) Starting the VM...(swarm-master) Check network to re-create if needed...(swarm-master) Waiting for an IP...Waiting for machine to be running, this may take a few minutes...Detecting operating system of created instance...Waiting for SSH to be available...Detecting the provisioner...Provisioning with boot2docker...Copying certs to the local machine directory...Copying certs to the remote machine...Setting Docker configuration on the remote daemon...Configuring swarm...Checking connection to Docker...Docker is up and running!To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: C:Program FilesDockerDockerResourcesindocker-machine.exe env swarm-master          

Let’s check our cluster status:

11:00:46 [G] docker-swarm> docker-machine lsNAME            ACTIVE   DRIVER       STATE     URL                         SWARM                   DOCKER    ERRORSswarm-cluster   *        virtualbox   Running   tcp://192.168.99.100:2376                           v1.12.3swarm-master    -        virtualbox   Running   tcp://192.168.99.101:2376   swarm-master (master)   v1.12.3

As you can see we have two virtual machines, one of them is the master.

Adding Nodes

It’s time to add nodes. The command for adding a node is very similar to creating the master. The only difference is that you don’t specify the –swarm-master flag:

docker-machine create   -d virtualbox   --swarm   --swarm-discovery token://e18fe8919e3c504e7f00284879fa9933   agent-smith  Running pre-create checks...Creating machine...(agent-smith) Copying C:Users	he_g.dockermachinecacheoot2docker.iso to C:Users	he_g.dockermachinemachinesagent-smithoot2docker.iso...(agent-smith) Creating VirtualBox VM...(agent-smith) Creating SSH key...(agent-smith) Starting the VM...(agent-smith) Check network to re-create if needed...(agent-smith) Waiting for an IP...Waiting for machine to be running, this may take a few minutes...Detecting operating system of created instance...Waiting for SSH to be available...Detecting the provisioner...Provisioning with boot2docker...Copying certs to the local machine directory...Copying certs to the remote machine...Setting Docker configuration on the remote daemon...Configuring swarm...Checking connection to Docker...Docker is up and running!To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: C:Program FilesDockerDockerResourcesindocker-machine.exe env agent-smith  

You can name your nodes however you like, as long as the names are unique. I chose “agent-smith” for this node. Let’s create another agent called “agent-007”

docker-machine create   -d virtualbox   --swarm   --swarm-discovery token://e18fe8919e3c504e7f00284879fa9933   agent-007

Checking the cluster now we see the two new nodes:

> docker-machine lsNAME            ACTIVE   DRIVER       STATE     URL                         SWARM                   DOCKER    ERRORSagent-007       -        virtualbox   Running   tcp://192.168.99.103:2376   swarm-master            v1.12.3agent-smith     -        virtualbox   Running   tcp://192.168.99.102:2376   swarm-master            v1.12.3swarm-cluster   *        virtualbox   Running   tcp://192.168.99.100:2376                           v1.12.3swarm-master    -        virtualbox   Running   tcp://192.168.99.101:2376   swarm-master (master)   v1.12.3

The cluster is up and running. Now you can run containers on the cluster and the Swarm will make sure to run them on one of the nodes that has enough capacity. Here it is running the hello-world container that just prints “Hello from Docker!” and some help text:

docker run hello-worldHello from Docker!This message shows that your installation appears to be working correctly.To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. 3. The Docker daemon created a new container from that image which runs the    executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it    to your terminal.To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bashShare images, automate workflows, and more with a free Docker Hub account: https://hub.docker.comFor more examples and ideas, visit: https://docs.docker.com/engine/userguide/

Give Docker Swarm a try???it is a relatively painless way to get into the world of container orchestration. If you want to graduate to the big leagues take a look at Kubernetes.

devx-admin

devx-admin

Share the Post:
Poland Energy Future

Westinghouse Builds Polish Power Plant

Westinghouse Electric Company and Bechtel have come together to establish a formal partnership in order to design and construct Poland’s inaugural nuclear power plant at

EV Labor Market

EV Industry Hurting For Skilled Labor

The United Auto Workers strike has highlighted the anticipated change towards a future dominated by electric vehicles (EVs), a shift which numerous people think will

Soaring EV Quotas

Soaring EV Quotas Spark Battle Against Time

Automakers are still expected to meet stringent electric vehicle (EV) sales quotas, despite the delayed ban on new petrol and diesel cars. Starting January 2023,

Affordable Electric Revolution

Tesla Rivals Make Bold Moves

Tesla, a name synonymous with EVs, has consistently been at the forefront of the automotive industry’s electric revolution. The products that Elon Musk has developed

Poland Energy Future

Westinghouse Builds Polish Power Plant

Westinghouse Electric Company and Bechtel have come together to establish a formal partnership in order to design and construct Poland’s inaugural nuclear power plant at the Lubiatowo-Kopalino site in Pomerania.

EV Labor Market

EV Industry Hurting For Skilled Labor

The United Auto Workers strike has highlighted the anticipated change towards a future dominated by electric vehicles (EVs), a shift which numerous people think will result in job losses. However,

Soaring EV Quotas

Soaring EV Quotas Spark Battle Against Time

Automakers are still expected to meet stringent electric vehicle (EV) sales quotas, despite the delayed ban on new petrol and diesel cars. Starting January 2023, more than one-fifth of automobiles

Affordable Electric Revolution

Tesla Rivals Make Bold Moves

Tesla, a name synonymous with EVs, has consistently been at the forefront of the automotive industry’s electric revolution. The products that Elon Musk has developed are at the forefront because

Sunsets' Technique

Inside the Climate Battle: Make Sunsets’ Technique

On February 12, 2023, Luke Iseman and Andrew Song from the solar geoengineering firm Make Sunsets showcased their technique for injecting sulfur dioxide (SO₂) into the stratosphere as a means

AI Adherence Prediction

AI Algorithm Predicts Treatment Adherence

Swoop, a prominent consumer health data company, has unveiled a cutting-edge algorithm capable of predicting adherence to treatment in people with Multiple Sclerosis (MS) and other health conditions. Utilizing artificial

Personalized UX

Here’s Why You Need to Use JavaScript and Cookies

In today’s increasingly digital world, websites often rely on JavaScript and cookies to provide users with a more seamless and personalized browsing experience. These key components allow websites to display

Geoengineering Methods

Scientists Dimming the Sun: It’s a Good Thing

Scientists at the University of Bern have been exploring geoengineering methods that could potentially slow down the melting of the West Antarctic ice sheet by reducing sunlight exposure. Among these

why startups succeed

The Top Reasons Why Startups Succeed

Everyone hears the stories. Apple was started in a garage. Musk slept in a rented office space while he was creating PayPal with his brother. Facebook was coded by a

Bold Evolution

Intel’s Bold Comeback

Intel, a leading figure in the semiconductor industry, has underperformed in the stock market over the past five years, with shares dropping by 4% as opposed to the 176% return

Semiconductor market

Semiconductor Slump: Rebound on the Horizon

In recent years, the semiconductor sector has faced a slump due to decreasing PC and smartphone sales, especially in 2022 and 2023. Nonetheless, as 2024 approaches, the industry seems to

Elevated Content Deals

Elevate Your Content Creation with Amazing Deals

The latest Tech Deals cater to creators of different levels and budgets, featuring a variety of computer accessories and tools designed specifically for content creation. Enhance your technological setup with

Learn Web Security

An Easy Way to Learn Web Security

The Web Security Academy has recently introduced new educational courses designed to offer a comprehensible and straightforward journey through the intricate realm of web security. These carefully designed learning courses

Military Drones Revolution

Military Drones: New Mobile Command Centers

The Air Force Special Operations Command (AFSOC) is currently working on a pioneering project that aims to transform MQ-9 Reaper drones into mobile command centers to better manage smaller unmanned

Tech Partnership

US and Vietnam: The Next Tech Leaders?

The US and Vietnam have entered into a series of multi-billion-dollar business deals, marking a significant leap forward in their cooperation in vital sectors like artificial intelligence (AI), semiconductors, and

Huge Savings

Score Massive Savings on Portable Gaming

This week in tech bargains, a well-known firm has considerably reduced the price of its portable gaming device, cutting costs by as much as 20 percent, which matches the lowest

Cloudfare Protection

Unbreakable: Cloudflare One Data Protection Suite

Recently, Cloudflare introduced its One Data Protection Suite, an extensive collection of sophisticated security tools designed to protect data in various environments, including web, private, and SaaS applications. The suite

Drone Revolution

Cool Drone Tech Unveiled at London Event

At the DSEI defense event in London, Israeli defense firms exhibited cutting-edge drone technology featuring vertical-takeoff-and-landing (VTOL) abilities while launching two innovative systems that have already been acquired by clients.

2D Semiconductor Revolution

Disrupting Electronics with 2D Semiconductors

The rapid development in electronic devices has created an increasing demand for advanced semiconductors. While silicon has traditionally been the go-to material for such applications, it suffers from certain limitations.

Cisco Growth

Cisco Cuts Jobs To Optimize Growth

Tech giant Cisco Systems Inc. recently unveiled plans to reduce its workforce in two Californian cities, with the goal of optimizing the company’s cost structure. The company has decided to

FAA Authorization

FAA Approves Drone Deliveries

In a significant development for the US drone industry, drone delivery company Zipline has gained Federal Aviation Administration (FAA) authorization, permitting them to operate drones beyond the visual line of

Mortgage Rate Challenges

Prop-Tech Firms Face Mortgage Rate Challenges

The surge in mortgage rates and a subsequent decrease in home buying have presented challenges for prop-tech firms like Divvy Homes, a rent-to-own start-up company. With a previous valuation of

Lighthouse Updates

Microsoft 365 Lighthouse: Powerful Updates

Microsoft has introduced a new update to Microsoft 365 Lighthouse, which includes support for alerts and notifications. This update is designed to give Managed Service Providers (MSPs) increased control and

Website Lock

Mysterious Website Blockage Sparks Concern

Recently, visitors of a well-known resource website encountered a message blocking their access, resulting in disappointment and frustration among its users. While the reason for this limitation remains uncertain, specialists