Docker Swarm

Let’s dive into Docker Swarm and learn basic commands related to it.

Docker swarm

A swarm is a set of nodes that are either physical or virtual servers. Each swarm must have at least one manager node that manages the service and delegates tasks to the worker nodes. A service can be run by a single container or multiple containers. The container image that is to be used is specified when creating a service.

If you’ve not previously used Swarm, the following command returns a report, which also contains a line saying Swarm: inactive.

docker system info

Execute the following command to define your machine as the swarm manager:

docker swarm init

The result would be similar to this:

Swarm initialized: current node (yvhtgc5lypxnygtijxh) is now a manager.

To add a worker to this swarm, run the following command:

  docker swarm join --token
  SWMTKN-1-0p6w735dvmxq82dcmpcxnykj3obmpfm0wqwcdg4kc17irwmu9y
  192.168.65.3:2377

To add a manager to this swarm, run 'docker swarm join-token manager'
and follow the instructions.

Practice

You can run all of the commands discussed in this lesson in the terminal below:

Get hands-on with 1400+ tech skills courses.