Feedback

Chat Icon

Painless Docker - 2nd Edition

A Comprehensive Guide to Mastering Docker and its Ecosystem

Understanding How Docker Swarm Works
86%

Multi-manager Docker Swarm

We previously created a Swarm cluster with one manager node. We then promoted one of the worker nodes to a manager node. But what is the difference between these two types of nodes? Additionally, what is the difference between a single-manager cluster and a multi-manager cluster? This section provides the answers.

Firstly, there are two types of nodes in a Swarm cluster:

  • Manager nodes: These nodes are responsible for managing the cluster, including scheduling containers on worker nodes and maintaining the cluster state. Only manager nodes can run the docker swarm commands.
  • Worker nodes: These nodes are responsible solely for running containers and do not participate in managing the cluster.

When you start a service, the manager nodes will schedule containers on all nodes, including the manager nodes themselves. This means that manager nodes can also run containers (unless you explicitly prevent it). Therefore, there are no differences between manager nodes and worker nodes except that managers have the additional responsibility of managing the entire cluster.

If desired, you can prevent the scheduling of containers on manager nodes. This is useful when you want to dedicate manager nodes solely to managing the cluster and not running containers. There are two options to achieve this:

Option 1: You can simply drain the manager nodes like we did in the previous section:

export NODE_HOSTNAME=manager

docker node update --availability drain $NODE_HOSTNAME

Option 2: You can use the constraint option when you create the service to specify that the service should not run on the manager nodes:

This is an example:

docker service create \
    --name webserver-another-test \
    -p 8002:80 \
    --constraint node.role==worker \
    --replicas 10 \
    nginx:1.29.5

Now check where the new service is running:

docker service ps webserver-another-test \
    --format "table {{.Name}}\t{{.Node}}"

Painless Docker - 2nd Edition

A Comprehensive Guide to Mastering Docker and its Ecosystem

Enroll now to unlock all content and receive all future updates for free.

Unlock now  $31.99$25.59

Hurry! This limited time offer ends in:

To redeem this offer, copy the coupon code below and apply it at checkout:

Learn More