You use Docker Swarm to host and schedule a cluster of Docker containers. This section introduces you to Docker Swarm by teaching you how to create a swarm
on your local machine using Docker Machine and VirtualBox.

Prerequisites

Make sure your local system has VirtualBox installed. If you are using macOS
or Windows and have installed Docker, you should have VirtualBox already
installed.

Create a Docker Swarm

Docker Machine gets hosts ready to run Docker containers. Each node in your
Docker Swarm must have access to Docker to pull images and run them in
containers. Docker Machine manages all this provisioning for your swarm.

Before you create a swarm with docker-machine, you associate each
node with a discovery service. This example uses the token discovery
service hosted by Docker Hub (only for testing/dev, not for production).
This discovery service associates a token with instances of the Docker
Daemon running on each node. Other discovery service backends such as
etcd, consul, and zookeeper are available.

The swarm create command returned the fe0cc96a72cf04dba8c1c4aa79536ec3
token.
Note: This command relies on Docker Swarm’s hosted discovery service. If
this service is having issues, this command may fail. In this case, see
information on using other types of discovery backends. Check
the status page for service availability.

Save the token in a safe place.

You use this token in the next step to create a Docker Swarm.

Launch the Swarm manager

A single system in your network is known as your Docker Swarm manager. The swarm
manager orchestrates and schedules containers on the entire cluster. The swarm
manager rules a set of agents (also called nodes or Docker nodes).

Swarm agents are responsible for hosting containers. They are regular docker
daemons and you can communicate with them using the Docker Engine API.

You can see that each agent and the master all have port 2376 exposed. When you create a swarm, you can use any port you like and even different ports on different nodes. Each swarm node runs the swarm agent container.

The master is running both the swarm manager and a swarm agent container. This isn’t recommended in a production environment because it can cause problems with agent failover. However, it is perfectly fine to do this in a learning environment like this one.

$ docker run hello-world
Hello 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.
(Assuming it was not already locally available.)
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:

Where to go next

At this point, you’ve installed Docker Swarm by pulling the latest image of
it from Docker Hub. Then, you built and ran a swarm on your local machine
using VirtualBox. If you want, you can onto read an overview of Docker Swarm
features. Alternatively, you can develop a more in-depth view of Swarm by
manually installing Swarm on a network.