Outils pour utilisateurs

Outils du site


notes:docker_swarm

Docker Swarm

Install Docker

Install using the apt repository

Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker apt repository. Afterward, you can install and update Docker from the repository.

Set up Docker's apt repository.

To setup official's Docker repository, run (as root):

<cli bash> # Add Docker's official GPG key: apt update apt install ca-certificates curl install -m 0755 -d /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources: echo \

"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null

apt update </cli>

Install the Docker packages.

To install the latest version, run (as root): <cli> apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin </cli>

Create a swarm

After you complete the setup steps, you're ready to create a swarm. Make sure the Docker Engine daemon is started on the host machines.

Open a terminal and ssh into the machine where you want to run your manager node. This example we uses a machine named docker00.

Run the following command to create a new swarm:

docker swarm init --advertise-addr <MANAGER-IP>

In the tutorial, the following command creates a swarm on the manager1 machine:

<cli> root@docker01:~# docker swarm init –advertise-addr 192.168.80.10 Swarm initialized: current node (dxn1zf6l61qsb1josjja83ngz) is now a manager.

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

  docker swarm join --token SWMTKN-1-2[snip]wlr 192.168.80.10:2377

To add a manager to this swarm, run docker swarm join-token manager and follow the instructions. </cli>

Take note of the token provided

Adding manager node

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

Adding worker node

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

<cli> root@docker01:~# docker swarm join \

  1. -token SWMTKN-1-2[snip]wlr \

192.168.80.10:2377 </cli>

The –advertise-addr flag configures the manager node to publish its address as 192.168.80.10. The other nodes in the swarm must be able to access the manager at the IP address.

The output includes the commands to join new nodes to the swarm. Nodes will join as managers or workers depending on the value for the –token flag.

Validate the swarm status

Run docker info to view the current state of the swarm:

<cli> root@docker00:~# docker info Client: Docker Engine - Community Version: 28.0.1 Context: default Debug Mode: false Plugins:

buildx: Docker Buildx (Docker Inc.)
  Version:  v0.21.1
  Path:     /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
  Version:  v2.33.1
  Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server: Containers: 6

Running: 3
Paused: 0
Stopped: 3

Images: 6 Server Version: 28.0.1 Storage Driver: overlay2

Backing Filesystem: extfs
...snip...

Swarm: active

NodeID: nh0izhq4pa2plmjdvy00f8um7
Is Manager: true
ClusterID: mbwi9gcqsueen8mcanvme3zc8
Managers: 1
Nodes: 3
...snip...

</cli>

Run the docker node ls command to view information about nodes:

<cli> root@docker00:~# docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION nh0izhq4pa2plmjdvy00f8um7 * deb-docker00 Ready Active Leader 28.0.1 7m0t8hrymi0jlmy1jpf85tknt deb-docker01 Ready Active 28.0.1 tebmpkb8og8ko2jfa2zq0z5oc deb-docker02 Ready Active 28.0.1 </cli>

The * next to the node ID indicates that you're currently connected on this node.

Docker Engine Swarm mode automatically names the node with the machine host name.

In my labs, I've setup 3 nodes, deb-docker00, deb-docker01, deb-docker02.

notes/docker_swarm.txt · Dernière modification : de frater