This tutorial introduces you to the features of Docker Engine Swarm mode. You may want to familiarize yourself with the key concepts before you begin.
The tutorial guides you through the following activities:
This tutorial uses Docker Engine CLI commands entered on the command line of a terminal window. You should be able to install Docker on networked machines and be comfortable with running commands in the shell of your choice.
If you are brand new to Docker, see About Docker Engine.
To run this tutorial, you need the following:
The tutorial uses three networked host machines as nodes in the swarm. These can be virtual machines on your PC, in a data center, or on a cloud service provider. This tutorial uses the following machine names:
Note: You can follow many of the tutorial steps to test single-node swarm as well, in which case you need only one host. Multi-node commands will not work, but you can initialize a swarm, create services, and scale them.
This tutorial requires Docker Engine 1.12 or newer on each of the host machines. Install Docker Engine and verify that the Docker Engine daemon is running on each of the machines. You can get the latest version of Docker Engine as follows:
If you are using Linux based physical computers or cloud-provided computers as hosts, simply follow the Linux install instructions for your platform. Spin up the three machines, and you are ready. You can test both single-node and multi-node swarm scenarios on Linux machines.
Alternatively, install the latest Docker for Mac or Docker for Windows application on a one computer. You can test both single-node and multi-node swarm from this computer, but you will need to use Docker Machine to test the multi-node scenarios.
worker2in our example). After you create the nodes, you can run all swarm commands as shown from the Mac terminal or Windows PowerShell with Docker for Mac or Docker for Windows running.
The IP address must be assigned to a network interface available to the host operating system. All nodes in the swarm must be able to access the manager at the IP address.
Because other nodes contact the manager node on its IP address, you should use a fixed IP address.
You can run
ifconfig on Linux or macOS to see a list of the
available network interfaces.
If you are using Docker Machine, you can get the manager IP with either
docker-machine ls or
docker-machine ip <MACHINE-NAME> — for example,
docker-machine ip manager1.
The tutorial uses
The following ports must be available. On some systems, these ports are open by default.
If you are planning on creating an overlay network with encryption (
you will also need to ensure port 50 (ESP) is open.
After you have set up your environment, you are ready to create a swarm.