Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| notes:docker_swarm [2025/03/05 11:13] – créée frater | notes:docker_swarm [2025/11/13 11:44] (Version actuelle) – frater | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ====== Docker Swarm ====== | ====== Docker Swarm ====== | ||
| + | {{tag> | ||
| + | ===== Install Docker ===== | ||
| + | [[https:// | ||
| + | ==== 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' | ||
| + | |||
| + | |||
| + | To setup official' | ||
| + | |||
| + | <cli bash> | ||
| + | # Add Docker' | ||
| + | apt update | ||
| + | apt install ca-certificates curl | ||
| + | install -m 0755 -d / | ||
| + | curl -fsSL https:// | ||
| + | chmod a+r / | ||
| + | |||
| + | # Add the repository to Apt sources: | ||
| + | echo \ | ||
| + | "deb [arch=$(dpkg --print-architecture) signed-by=/ | ||
| + | $(. / | ||
| + | tee / | ||
| + | apt update | ||
| + | </ | ||
| + | |||
| + | ==== Install the Docker packages. ==== | ||
| + | |||
| + | To install the latest version, run (as '' | ||
| + | <cli> | ||
| + | apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin | ||
| + | </ | ||
| + | |||
| + | ===== 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 '' | ||
| + | |||
| + | Run the following command to create a new swarm: | ||
| + | |||
| + | <code bash> | ||
| + | docker swarm init --advertise-addr < | ||
| + | </ | ||
| + | |||
| + | In the tutorial, the following command creates a swarm on the manager1 machine: | ||
| + | |||
| + | <cli> | ||
| + | root@docker01: | ||
| + | Swarm initialized: | ||
| + | |||
| + | To add a worker to this swarm, run the following command: | ||
| + | |||
| + | docker swarm join --token SWMTKN-1-2[snip]wlr 192.168.80.10: | ||
| + | |||
| + | To add a manager to this swarm, run '' | ||
| + | </ | ||
| + | |||
| + | <WRAP center round important> | ||
| + | Take note of the token provided | ||
| + | </ | ||
| + | |||
| + | ==== Adding manager node ==== | ||
| + | |||
| + | |||
| + | To add a manager to this swarm, run '' | ||
| + | |||
| + | ==== Adding worker node ==== | ||
| + | |||
| + | To add a worker to this swarm, run the following command: | ||
| + | |||
| + | <cli> | ||
| + | root@docker01: | ||
| + | --token SWMTKN-1-2[snip]wlr \ | ||
| + | 192.168.80.10: | ||
| + | </ | ||
| + | |||
| + | The '' | ||
| + | |||
| + | 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 '' | ||
| + | |||
| + | ==== Validate the swarm status ==== | ||
| + | |||
| + | Run '' | ||
| + | |||
| + | <cli> | ||
| + | root@docker00: | ||
| + | Client: Docker Engine - Community | ||
| + | | ||
| + | | ||
| + | Debug Mode: false | ||
| + | | ||
| + | buildx: Docker Buildx (Docker Inc.) | ||
| + | Version: | ||
| + | Path: / | ||
| + | compose: Docker Compose (Docker Inc.) | ||
| + | Version: | ||
| + | Path: / | ||
| + | |||
| + | Server: | ||
| + | | ||
| + | Running: 3 | ||
| + | Paused: 0 | ||
| + | Stopped: 3 | ||
| + | | ||
| + | | ||
| + | | ||
| + | Backing Filesystem: extfs | ||
| + | ...snip... | ||
| + | Swarm: active | ||
| + | NodeID: nh0izhq4pa2plmjdvy00f8um7 | ||
| + | Is Manager: true | ||
| + | ClusterID: mbwi9gcqsueen8mcanvme3zc8 | ||
| + | Managers: 1 | ||
| + | Nodes: 3 | ||
| + | ...snip... | ||
| + | </ | ||
| + | |||
| + | Run the '' | ||
| + | |||
| + | <cli> | ||
| + | root@docker00: | ||
| + | ID HOSTNAME | ||
| + | nh0izhq4pa2plmjdvy00f8um7 * | ||
| + | 7m0t8hrymi0jlmy1jpf85tknt | ||
| + | tebmpkb8og8ko2jfa2zq0z5oc | ||
| + | </ | ||
| + | |||
| + | 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. | ||
| + | |||
| + | <WRAP center round info> | ||
| + | In my labs, I've setup 3 nodes, deb-docker00, | ||
| + | </ | ||