Simulate a Docker Swarm Cluster on a Single Machine Using Multipass
Published: 2023-10-11
Introduction
Have you ever needed to run multiple Docker nodes on a single machine, perhaps to experiment with container orchestration or test a distributed application locally?
Setting up multiple virtual machines (VMs), installing Docker on each one, and configuring them to communicate with one another can be time-consuming. Multipass makes this process much easier by allowing you to quickly create and manage lightweight Ubuntu virtual machines.
In this article, we’ll use Multipass on a Windows 10 machine to create a five-node Docker environment and configure those nodes as a Docker Swarm cluster.
What is Multipass?
Imagine you’re using a Windows 10 machine and want to simulate a multi-node Docker environment. You need multiple virtual machines that can run Docker, communicate with one another, and work together as a single cluster using Docker Swarm.
You could manually create and configure these virtual machines, but that would involve several repetitive steps. Multipass simplifies this process.
According to its creators, Multipass is a tool for quickly launching cloud-style Ubuntu virtual machines on Linux, macOS, and Windows.
One of its key advantages is its simplicity. Multipass provides ready-to-use VM images, including an image with Docker pre-installed. This means you can create Docker-enabled virtual machines without having to install and configure Docker on each one manually.
Getting Started with Multipass
For this tutorial, I’m using a Windows 10 machine and PowerShell to perform all the setup operations.
First, install Multipass on your Windows machine. Follow the installation instructions in the official Multipass documentation.
Once installed, open PowerShell and run the following command to verify the installation:
multipass version

If Multipass is installed correctly, the command displays the installed version information.
Creating Docker Nodes
Now that Multipass is installed, let’s create the virtual machines required for our Docker Swarm cluster.
For this example, we’ll create five nodes:
- Three manager nodes:
manager1,manager2, andmanager3. - Two worker nodes:
worker1andworker2.
You can create more or fewer nodes depending on your requirements and the resources available on your machine.
1. Check the available Multipass images.
Run the following command to list the images and blueprints available through Multipass:
multipass find

Look for the Docker image, which provides an Ubuntu virtual machine with Docker pre-installed.
2. Create the first manager node.
Run the following command to create a VM named manager1 using the Docker image:
multipass launch docker --name manager1

3. Create the remaining manager nodes.
Repeat the command with different names to create the other two manager nodes:
multipass launch docker --name manager2
multipass launch docker --name manager3
4. Create the worker nodes.
Similarly, create two worker nodes:
multipass launch docker --name worker1
multipass launch docker --name worker2
An important point to understand is that Multipass doesn’t distinguish between manager and worker nodes. It simply creates virtual machines with Docker installed. The manager or worker role is assigned later when you configure the Docker Swarm cluster.
5. Verify that all virtual machines have been created.
Run the following command to list the available Multipass instances:
multipass list

You should now see all five virtual machines listed.
Great! We have successfully created the five Docker-enabled nodes required for our cluster.
Creating a Docker Swarm
Now that all the nodes are ready, the next step is to configure them as a Docker Swarm cluster.
Since this article focuses on using Multipass to simulate a multi-node Docker environment, I won’t cover Docker Swarm configuration in detail.
1. Connect to a virtual machine.
You can access any Multipass VM directly from PowerShell using the multipass shell command.
For example, to connect to the first manager node:
multipass shell manager1

This opens a shell inside the selected Ubuntu virtual machine, where you can execute Docker commands.
2. Initialize the Docker Swarm and add the remaining nodes.
To create the cluster:
- Initialize the Swarm on
manager1usingdocker swarm init. - Use the manager join token to add
manager2andmanager3as manager nodes. - Use the worker join token to add
worker1andworker2as worker nodes.
You’ll need to retrieve the appropriate join tokens from the initial manager and execute the corresponding join commands on the other nodes.
For detailed instructions, refer to the official Docker Swarm mode documentation.
3. Verify the Docker Swarm cluster.
Once all five nodes have joined the cluster, connect to any manager node and run:
docker node ls

The command displays all the nodes registered with the Swarm, along with their roles and availability.
You should now see three manager nodes and two worker nodes.
That’s it! You have successfully created a five-node Docker Swarm cluster running entirely on a single machine.
You can now experiment with Docker Swarm features such as service deployment, overlay networking, service discovery, and load balancing.
Cleaning Up
Once you’re done experimenting with the Docker Swarm cluster, you may want to remove the virtual machines to free up your system resources.
Multipass provides two commands for this purpose:
- Delete: Stops and deletes the VM instance, but retains its underlying data so that it can be recovered later using
multipass recover. - Purge: Permanently removes previously deleted instances and their associated data.
1. Delete all virtual machines.
Run the following command to delete all Multipass instances:
multipass delete --all

At this point, the instances are deleted but haven’t been permanently removed. You can still recover them if needed.
2. Permanently remove the deleted virtual machines.
To permanently remove all deleted instances, run:
multipass purge

You can also combine both operations into a single command:
multipass delete --purge --all
Deleting individual virtual machines
If you want to remove only specific nodes instead of deleting all instances, specify the VM name:
multipass delete --purge manager1
You can repeat this command for any other nodes you want to remove.
For additional details, refer to the Multipass documentation on removing an instance.
Conclusion
Multipass provides a simple and convenient way to simulate a multi-node environment on a single machine. By combining Multipass with Docker Swarm, you can quickly create a distributed Docker environment without requiring multiple physical machines.
This setup is particularly useful for local development, learning container orchestration, experimenting with Docker Swarm, and testing distributed application deployments.
I hope this tutorial helps you get started with Multipass and build your own local Docker Swarm environment.