Docker Swarm is a clustering solution that brings together different hosts/nodes into a single manageable unit that you can orchestrate the life cycle of your containers in. Managers and workers operate over the Control Plane which defines how orders are sent around the swarm.
Manager Nodes are authority figures inside a swarm. Each node has its own RAFT database that stores their configurations and process data that allows them to keep authority. Each manager encrypts its traffic to ensure its integrity and trust that they are able to manage the swarm securely. Essentially, a manager node is a worker that is able to control the swarm.
Workers Nodes - are actually serve the processes for the swarm. They are the services that make the swarm work. Each Worker is made up of a Task/Executor and a Container.
Tasks - are commands that control their associated container. A common task is one that launches a container. These tasks are sent by Manager Nodes to Worker Nodes.
https://docs.docker.com/engine/reference/commandline/swarm_init/
To initialize the swarm in your current environment:
docker swarm init
This one command does a lot of things:
Generally in cloud services, you will need to specify an IP address that the service can be recognized with. This can be done with the --advertise-addr
flag.
docker swarm init --advertise-addr {ip_address}
https://docs.docker.com/engine/reference/commandline/swarm_join/
If you have a virtual machine that you wish to recruit as a node on a swarm:
docker swarm join {join_info}
The join information is obtained by the leader of the swarm using the following commands:
docker swarm join-token manager
docker swarm join-token worker
Each command will display the command containing the appropriate token and IP address that should be used on each of the other nodes that you wish to recruit.
Node commands are designed for bringing servers in and out of the swarm, promoting workers to managers, and demoting managers to workers.
https://docs.docker.com/engine/reference/commandline/node_ls/
To list all of the nodes in the swarm:
docker node ls
The “Manager Status” indicates whether each node is a manager or a worker. There can only be one leader, but other managers will be identified as “Reachable”.
https://docs.docker.com/engine/reference/commandline/node_update/
docker node update --role {manager/worker} {node_id}
Service commands replace the docker container run
for swarms. In a production environment, individual containers are not really accessed. Instead, commands are given to the docker service to automatically orchestrate the processes among all of the swarm containers.
https://docs.docker.com/engine/reference/commandline/service_ls/
To list all of the services currently running in the swarm:
docker service ls
https://docs.docker.com/engine/reference/commandline/service_create/
To create a service:
docker service create {image}
https://docs.docker.com/engine/reference/commandline/service_ps/
To list all of the containers currently running in a service:
docker service ps {service_id}
Every service can have many nodes, both manager and worker. This helps determine which nodes are designated to which service.
https://docs.docker.com/engine/reference/commandline/service_update/
There are a lot of ways to update a service, from reserving different amounts of resources, to changing how updates are rolled out, to inspecting its health, and so much more. This document will only list a few.
To add more replicas to (or remove replicas from) a service:
docker service update {service_id} --replicas {number}
The Routing Mesh is an incoming or ingress network that distributes packets for a service to the tasks for that service. This spans all of the nodes and uses a Linux Kernel called IPVS. The primary purpose of the routing mesh is to create stateless load balancing on all of the nodes and listen for traffic.