Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente |
elearning:workbooks:docker3:drf04 [2023/12/16 14:19] – admin | elearning:workbooks:docker3:drf04 [2024/02/21 13:40] (Version actuelle) – admin |
---|
~~PDF:LANDSCAPE~~ | ~~PDF:LANDSCAPE~~ |
| |
Version : **2023.01** | Version : **2024.01** |
| |
Last update : ~~LASTMOD~~ | Dernière mise-à-jour : ~~LASTMOD~~ |
| |
======DOE605 - Docker Compose, Docker Machine and Docker Swarm====== | ======DOF605 - Docker Compose, Docker Machine et Docker Swarm====== |
| |
=====Module content===== | =====Contenu du Module===== |
| |
* **DOE605 - Docker Compose, Docker Machine and Docker Swarm** * Module Contents | * **DOF605 - Docker Compose, Docker Machine et Docker Swarm** |
* Module content | * Contenu du Module |
* LAB #1 - Docker Compose | * LAB #1 - Docker Compose |
* 1.1 - Installation | * 1.1 - Installation |
* 1.2 - Installing Wordpress with Docker Compose | * 1.2 - Installer Wordpress avec Docker Compose |
* LAB #2 - Docker Machine | * LAB #2 - Docker Machine |
* 2.1 - Introduction | * 2.1 - Présentation |
* 2.2 - Creating Docker Virtual Machines | * 2.2 - Création de Machines Virtuelles Docker |
* 2.3 - Listing Docker VMs | * 2.3 - Lister les VM Docker |
* 2.4 - Obtaining VM IP addresses | * 2.4 - Obtenir l'adresse IP des VM |
* 2.5 - Connecting to a Docker VM | * 2.5 - Se connecter à une VM Docker |
* LAB #3 - Docker Swarm | * LAB #3 - Docker Swarm |
* 3.1 - Overview | * 3.1 - Présentation |
* 3.2 - Initializing Docker Swarm | * 3.2 - Initialiser Docker Swarm |
* 3.3 - Leader status | * 3.3 - Le Statut Leader |
* 3.4 - Joining the Swarm | * 3.4 - Rejoindre le Swarm |
* 3.5 - Viewing Swarm Information | * 3.5 - Consulter les Informations de Swarm |
* 3.6 - Starting a Service | * 3.6 - Démarrer un Service |
* 3.7 - Scaling Up and Scaling Down a Service | * 3.7 - Augmentation et Réduction du Service |
* 3.8 - Checking Node Status | * 3.8 - Consulter le Statut d'un Nœud |
* 3.9 - High Availability | * 3.9 - Haute Disponibilité |
* 3.10 - Deleting a Service | * 3.10 - Supprimer un Service |
* 3.11 - Backing up Docker Swarm | * 3.11 - Sauvegarder Docker Swarm |
* 3.12 - Restoring Docker Swarm | * 3.12 - Restaurer Docker Swarm |
| |
=====LAB #1 - Docker Compose===== | =====LAB #1 - Docker Compose===== |
| |
Docker Compose is a utility for compiling images and managing multiple containers, all integrated into a single software application. Its role is to make it easier to handle multiple interconnected elements. To do this, Docker Compose uses a file called **docker-compose.yml** in **YAML** format. | Docker Compose est un utilitaire de compilation d'images et de gestion de conteneurs multiples, tous intégrés dans une seule et unique application logicielle. Son rôle est de rendre plus aisée la manipulation d'éléments multiples interconnectés. Pour ce faire, Docker Compose utilise un fichier dénommé **docker-compose.yml** au format **YAML**. |
| |
This file, called by the **docker-compose build** command, begins with an **image** or **build** keyword, depending on whether the image is retrieved from a registry or comes from the directory cited in the file. The rest of the file contains instructions for defining the compilation of the constituent images, for linking containers and for defining the environment. | Ce fichier, appelé par la commande **docker-compose build** commence avec un mot clef **image** ou **build** selon que l'image est récupérée sur un registre ou provient du répertoire cité dans le fichier. Le reste du fichier contient des instructions pour définir la compilation des images constituantes, pour lier des conteneurs et pour définir l'environnement. |
| |
Once it has been fully built, the application can then be run very simply using the docker-compose command, which reacts in the same way as the **docker** command, but this time on all the containers defined in the **docker-compose.yml** file. | Une fois totalement construite, l'application peut ensuite être pilotée très simplement par l'utilisation de la commande docker-compose qui réagit de la même manière que la commande **docker** mais cette fois-ci sur tous les conteneurs définis dans le fichier **docker-compose.yml**. |
| |
In this way it is possible to start the application with the **docker-compose up** command, stop it with the **docker-compose stop** command or restart it with the **docker-compose restart** command. In the same way as the **docker** command, the docker-compose command provides access to logs via the **docker-compose logs** command. | De cette façon il est possible de démarrer l'application avec la commande **docker-compose up**, de l'arrêter avec la commande **docker-compose stop** ou de la redémarrer avec la commande **docker-compose restart**. De la même manière que la commande **docker**, la commande docker-compose donne accès aux journaux grâce à la commande **docker-compose logs**. |
| |
====1.1 - Installation==== | ====1.1 - Installation==== |
| |
Retrieve docker-compose with **curl** : | Récupérez docker-compose avec **curl** : |
| |
<code> | <code> |
</code> | </code> |
| |
Check the installed version: | Vérifiez la version installée : |
| |
<code> | <code> |
</code> | </code> |
| |
Make **/usr/local/bin/docker-compose** executable: | Rendez **/usr/local/bin/docker-compose** exécutable : |
| |
<code> | <code> |
</code> | </code> |
| |
The options for the **docker-compose** command are: | Les options de la commande **docker-compose** sont : |
| |
<code> | <code> |
root@debian11:~# docker-compose --help | root@debian11:~# docker-compose --help |
| |
Usage: docker compose [OPTIONS] COMMAND | Usage: docker compose [OPTIONS] COMMAND |
| |
Docker Compose | Docker Compose |
| |
Options: | Options: |
--ansi string Control when to print ANSI control | --ansi string Control when to print ANSI control |
characters ("never"|"always"|"auto") | characters ("never"|"always"|"auto") |
(default "auto") | (default "auto") |
--compatibility Run compose in backward compatibility mode | --compatibility Run compose in backward compatibility mode |
--env-file string Specify an alternate environment file. | --env-file string Specify an alternate environment file. |
-f, --file stringArray Compose configuration files | -f, --file stringArray Compose configuration files |
--profile stringArray Specify a profile to enable | --profile stringArray Specify a profile to enable |
--project-directory string Specify an alternate working directory | --project-directory string Specify an alternate working directory |
(default: the path of the Compose file) | (default: the path of the Compose file) |
-p, --project-name string Project name | -p, --project-name string Project name |
| |
Commands: | Commands: |
build Build or rebuild services | build Build or rebuild services |
convert Converts the compose file to platform's canonical format | convert Converts the compose file to platform's canonical format |
cp Copy files/folders between a service container and the local filesystem | cp Copy files/folders between a service container and the local filesystem |
create Creates containers for a service. | create Creates containers for a service. |
down Stop and remove containers, networks | down Stop and remove containers, networks |
events Receives real time events from containers. | events Receive real time events from containers. |
exec Execute a command in a running container. | exec Execute a command in a running container. |
images List images used by the created containers | images List images used by the created containers |
kill Force stop service containers. | kill Force stop service containers. |
logs View output from containers | logs View output from containers |
ls List running compose projects | ls List running compose projects |
pause pause services | pause pause services |
port Print the public port for a port binding. | port Print the public port for a port binding. |
ps List containers | ps List containers |
pull Pull service images | pull Pull service images |
push Push service images | push Push service images |
restart Restart containers | restart Restart containers |
rm Removes stopped service containers | rm Removes stopped service containers |
run Run a one-off command on a service. | run Run a one-off command on a service. |
start Start services | start Start services |
stop Stop services | stop Stop services |
top Display the running processes | top Display the running processes |
unpause unpause services | unpause unpause services |
up Create and start containers | up Create and start containers |
| |
Run 'docker compose COMMAND --help' for more information on a command. | Run 'docker compose COMMAND --help' for more information on a command. |
</code> | </code> |
| |
====2.2 - Installing Wordpress with Docker Compose==== | ====1.2 - Installer Wordpress avec Docker Compose==== |
| |
Now create the **wordpress1** directory in /root : | Créez maintenant le répertoire **wordpress1** dans /root : |
| |
<code> | <code> |
</code> | </code> |
| |
Go into the directory and create the **docker-compose.yaml** file. | Placez-vous dans le répertoire et créer le fichier **docker-compose.yaml** |
| |
<code> | <code> |
</code> | </code> |
| |
Run the docker-compose command : | Exécutez la commande docker-compose : |
| |
<code> | <code> |
</code> | </code> |
| |
Check that wordpress is running: | Vérifiez que le Wordpress fonctionne : |
| |
<code> | <code> |
| |
<WRAP center round important 50%> | <WRAP center round important 50%> |
**Important** - The **docker-compose up** command is an alias to the **docker-compose build && docker-compose run** commands. The **-d** option has the same effect as its **docker** command counterpart. | **Important** - La commande **docker-compose up** est une abréviation des commandes **docker-compose build && docker-compose run**. L'option **-d** a le même effet de son homologue de la commande **docker**. |
</WRAP> | </WRAP> |
| |
=====LAB #2 - Docker Machine===== | =====LAB #2 - Docker Machine===== |
| |
====2.1 - Overview==== | ====2.1 - Présentation==== |
| |
Docker Machine is a tool that lets you install docker on virtual hosts and manage the hosts using commands specific to docker-machine. It is therefore possible to use this tool to create docker hosts locally, on the network, in a data centre or in the cloud (Azure, AWS, Digital Ocean for example). | Docker Machine est un outil qui vous permet d'installer docker sur des hôtes virtuels et de gérer les hôtes en utilisant des commandes spécifiques à docker-machine. Il est donc possible d'utiliser cet outil pour créer des hôtes docker localement, sur le réseau, dans un data center ou dans le cloud (Azure, AWS, Digital Ocean par exemple). |
| |
The docker-machine command set allows you to start, monitor, stop and restart a managed host, update the docker client/daemon and configure a docker client so that it 'talks' to your host machine. | Le jeu de commandes de docker-machine permet de démarrer, surveiller, arrêter et re-démarrer un hôte géré, de mettre à jour le client/daemon docker et de configurer un client docker afin qu'il "parle" à votre machine hôte. |
| |
To install docker-machine on your **debian11** VM, use the following command: | Pour installer docker-machine sur votre VM **debian11**, utilisez la commande suivante : |
| |
<code> | <code> |
</code> | </code> |
| |
====2.2 - Creating Docker Virtual Machines===== | ====2.2 - Création de Machines Virtuelles Docker===== |
| |
Creating a machine is done simply by using the **docker-machine** command with the **create** subcommand. This sub-command takes the **--driver** or **-d** option, which indicates the provider to be used: | La création d'une machine se fait simplement en utilisant la commande **docker-machine** avec la sous-commande **create**. Cette sous-commande prend l'option **--driver** ou **-d** qui indique le fournisseur à utiliser : |
| |
^ Provider ^ driver ^ | ^ Fournisseur ^ driver ^ |
| [[https://aws.amazon.com/fr/|Amazon Web Services]] | [[https://docs.docker.com/machine/drivers/aws/|amazonec2]] | | | [[https://aws.amazon.com/fr/|Amazon Web Services]] | [[https://docs.docker.com/machine/drivers/aws/|amazonec2]] | |
| [[https://www.digitalocean.com/|Digital Ocean]] | [[https://docs.docker.com/machine/drivers/digital-ocean/|digitalocean]] | | | [[https://www.digitalocean.com/|Digital Ocean]] | [[https://docs.docker.com/machine/drivers/digital-ocean/|digitalocean]] | |
| [[https://www.vmware.com/fr/products/vsphere.html|VMware vSphere]] | [[https://docs.docker.com/machine/drivers/vsphere/|vmwarevsphere]] | | | [[https://www.vmware.com/fr/products/vsphere.html|VMware vSphere]] | [[https://docs.docker.com/machine/drivers/vsphere/|vmwarevsphere]] | |
| |
Start by installing Oracle VirtualBox: | Commencez par installer Oracle VirtualBox: |
| |
<code> | <code> |
</code> | </code> |
| |
Create the **/etc/vbox/networks.conf** file: | Créez le fichier **/etc/vbox/networks.conf** : |
| |
<code> | <code> |
</code> | </code> |
| |
Now create the **manager1** virtual machine: | Créez maintenant la machine virtuelle **manager1** : |
| |
<code> | <code> |
</code> | </code> |
| |
The options for the **docker-machine** command are: | Les options de la commande **docker-machine** sont : |
| |
<code> | <code> |
| |
Options: | Options: |
--debug, -D Enable debug mode | --debug, -D Enable debug mode |
--storage-path, -s "/root/.docker/machine" Configures storage path [$MACHINE_STORAGE_PATH] | --storage-path, -s "/root/.docker/machine" Configures storage path [$MACHINE_STORAGE_PATH] |
--tls-ca-cert CA to verify remotes against [$MACHINE_TLS_CA_CERT] | --tls-ca-cert CA to verify remotes against [$MACHINE_TLS_CA_CERT] |
--tls-ca-key Private key to generate certificates [$MACHINE_TLS_CA_KEY] | --tls-ca-key Private key to generate certificates [$MACHINE_TLS_CA_KEY] |
--tls-client-cert Client cert to use for TLS [$MACHINE_TLS_CLIENT_CERT] | --tls-client-cert Client cert to use for TLS [$MACHINE_TLS_CLIENT_CERT] |
--tls-client-key Private key used in client TLS auth [$MACHINE_TLS_CLIENT_KEY] | --tls-client-key Private key used in client TLS auth [$MACHINE_TLS_CLIENT_KEY] |
--github-api-token Token to use for requests to the Github API [$MACHINE_GITHUB_API_TOKEN] | --github-api-token Token to use for requests to the Github API [$MACHINE_GITHUB_API_TOKEN] |
--native-ssh Use the native (Go-based) SSH implementation. [$MACHINE_NATIVE_SSH] | --native-ssh Use the native (Go-based) SSH implementation. [$MACHINE_NATIVE_SSH] |
--bugsnag-api-token BugSnag API token for crash reporting [$MACHINE_BUGSNAG_API_TOKEN] | --bugsnag-api-token BugSnag API token for crash reporting [$MACHINE_BUGSNAG_API_TOKEN] |
--help, -h show help | --help, -h show help |
--version, -v print the version | --version, -v print the version |
| |
Commands: | Commands: |
active Print which machine is active | active Print which machine is active |
config Print the connection config for machine | config Print the connection config for machine |
create Create a machine | create Create a machine |
env Display the commands to set up the environment for the Docker client | env Display the commands to set up the environment for the Docker client |
inspect Inspect information about a machine | inspect Inspect information about a machine |
ip Get the IP address of a machine | ip Get the IP address of a machine |
kill Kill a machine | kill Kill a machine |
ls List machines | ls List machines |
provision Re-provision existing machines | provision Re-provision existing machines |
regenerate-certs Regenerate TLS Certificates for a machine | regenerate-certs Regenerate TLS Certificates for a machine |
restart Restart a machine | restart Restart a machine |
rm Remove a machine | rm Remove a machine |
ssh Log into or run a command on a machine with SSH. | ssh Log into or run a command on a machine with SSH. |
scp Copy files between machines | scp Copy files between machines |
mount Mount or unmount a directory from a machine with SSHFS. | mount Mount or unmount a directory from a machine with SSHFS. |
start Start a machine | start Start a machine |
status Get the status of a machine | status Get the status of a machine |
stop Stop a machine | stop Stop a machine |
upgrade Upgrade a machine to the latest version of Docker | upgrade Upgrade a machine to the latest version of Docker |
url Get the URL of a machine | url Get the URL of a machine |
version Show the Docker Machine version or a machine docker version | version Show the Docker Machine version or a machine docker version |
help Shows a list of commands or help for one command | help Shows a list of commands or help for one command |
| |
Run 'docker-machine COMMAND --help' for more information on a command. | Run 'docker-machine COMMAND --help' for more information on a command. |
</code> | </code> |
| |
The options for the **create** subcommand of the **docker-machine** command are: | Les options de la sous-commande **create** de la commande **docker-machine** sont : |
| |
<code> | <code> |
Options: | Options: |
| |
--driver, -d "virtualbox" Driver to create machine with. [$MACHINE_DRIVER] | --driver, -d "virtualbox" Driver to create machine with. [$MACHINE_DRIVER] |
--engine-env [--engine-env option --engine-env option] Specify environment variables to set in the engine | --engine-env [--engine-env option --engine-env option] Specify environment variables to set in the engine |
--engine-insecure-registry [--engine-insecure-registry option --engine-insecure-registry option] Specify insecure registries to allow with the created engine | --engine-insecure-registry [--engine-insecure-registry option --engine-insecure-registry option] Specify insecure registries to allow with the created engine |
--engine-install-url "https://get.docker.com" Custom URL to use for engine installation [$MACHINE_DOCKER_INSTALL_URL] | --engine-install-url "https://get.docker.com" Custom URL to use for engine installation [$MACHINE_DOCKER_INSTALL_URL] |
--engine-label [--engine-label option --engine-label option] Specify labels for the created engine | --engine-label [--engine-label option --engine-label option] Specify labels for the created engine |
--engine-opt [--engine-opt option --engine-opt option] Specify arbitrary flags to include with the created engine in the form flag=value | --engine-opt [--engine-opt option --engine-opt option] Specify arbitrary flags to include with the created engine in the form flag=value |
--engine-registry-mirror [--engine-registry-mirror option --engine-registry-mirror option] Specify registry mirrors to use [$ENGINE_REGISTRY_MIRROR] | --engine-registry-mirror [--engine-registry-mirror option --engine-registry-mirror option] Specify registry mirrors to use [$ENGINE_REGISTRY_MIRROR] |
--engine-storage-driver Specify a storage driver to use with the engine | --engine-storage-driver Specify a storage driver to use with the engine |
--swarm Configure Machine to join a Swarm cluster | --swarm Configure Machine to join a Swarm cluster |
--swarm-addr addr to advertise for Swarm (default: detect and use the machine IP) | --swarm-addr addr to advertise for Swarm (default: detect and use the machine IP) |
--swarm-discovery Discovery service to use with Swarm | --swarm-discovery Discovery service to use with Swarm |
--swarm-experimental Enable Swarm experimental features | --swarm-experimental Enable Swarm experimental features |
--swarm-host "tcp://0.0.0.0:3376" ip/socket to listen on for Swarm master | --swarm-host "tcp://0.0.0.0:3376" ip/socket to listen on for Swarm master |
--swarm-image "swarm:latest" Specify Docker image to use for Swarm [$MACHINE_SWARM_IMAGE] | --swarm-image "swarm:latest" Specify Docker image to use for Swarm [$MACHINE_SWARM_IMAGE] |
--swarm-join-opt [--swarm-join-opt option --swarm-join-opt option] Define arbitrary flags for Swarm join | --swarm-join-opt [--swarm-join-opt option --swarm-join-opt option] Define arbitrary flags for Swarm join |
--swarm-master Configure Machine to be a Swarm master | --swarm-master Configure Machine to be a Swarm master |
--swarm-opt [--swarm-opt option --swarm-opt option] Define arbitrary flags for Swarm master | --swarm-opt [--swarm-opt option --swarm-opt option] Define arbitrary flags for Swarm master |
--swarm-strategy "spread" Define a default scheduling strategy for Swarm | --swarm-strategy "spread" Define a default scheduling strategy for Swarm |
--tls-san [--tls-san option --tls-san option] Support extra SANs for TLS certs | --tls-san [--tls-san option --tls-san option] Support extra SANs for TLS certs |
--virtualbox-boot2docker-url The URL of the boot2docker image. Defaults to the latest available version [$VIRTUALBOX_BOOT2DOCKER_URL] | --virtualbox-boot2docker-url The URL of the boot2docker image. Defaults to the latest available version [$VIRTUALBOX_BOOT2DOCKER_URL] |
--virtualbox-cpu-count "1" number of CPUs for the machine (-1 to use the number of CPUs available) [$VIRTUALBOX_CPU_COUNT] | --virtualbox-cpu-count "1" number of CPUs for the machine (-1 to use the number of CPUs available) [$VIRTUALBOX_CPU_COUNT] |
--virtualbox-disk-size "20000" Size of disk for host in MB [$VIRTUALBOX_DISK_SIZE] | --virtualbox-disk-size "20000" Size of disk for host in MB [$VIRTUALBOX_DISK_SIZE] |
--virtualbox-host-dns-resolver Use the host DNS resolver [$VIRTUALBOX_HOST_DNS_RESOLVER] | --virtualbox-host-dns-resolver Use the host DNS resolver [$VIRTUALBOX_HOST_DNS_RESOLVER] |
--virtualbox-hostonly-cidr "192.168.99.1/24" Specify the Host Only CIDR [$VIRTUALBOX_HOSTONLY_CIDR] | --virtualbox-hostonly-cidr "192.168.99.1/24" Specify the Host Only CIDR [$VIRTUALBOX_HOSTONLY_CIDR] |
--virtualbox-hostonly-nicpromisc "deny" Specify the Host Only Network Adapter Promiscuous Mode [$VIRTUALBOX_HOSTONLY_NIC_PROMISC] | --virtualbox-hostonly-nicpromisc "deny" Specify the Host Only Network Adapter Promiscuous Mode [$VIRTUALBOX_HOSTONLY_NIC_PROMISC] |
--virtualbox-hostonly-nictype "82540EM" Specify the Host Only Network Adapter Type [$VIRTUALBOX_HOSTONLY_NIC_TYPE] | --virtualbox-hostonly-nictype "82540EM" Specify the Host Only Network Adapter Type [$VIRTUALBOX_HOSTONLY_NIC_TYPE] |
--virtualbox-hostonly-no-dhcp Disable the Host Only DHCP Server [$VIRTUALBOX_HOSTONLY_NO_DHCP] | --virtualbox-hostonly-no-dhcp Disable the Host Only DHCP Server [$VIRTUALBOX_HOSTONLY_NO_DHCP] |
--virtualbox-import-boot2docker-vm The name of a Boot2Docker VM to import [$VIRTUALBOX_BOOT2DOCKER_IMPORT_VM] | --virtualbox-import-boot2docker-vm The name of a Boot2Docker VM to import [$VIRTUALBOX_BOOT2DOCKER_IMPORT_VM] |
--virtualbox-memory "1024" Size of memory for host in MB [$VIRTUALBOX_MEMORY_SIZE] | --virtualbox-memory "1024" Size of memory for host in MB [$VIRTUALBOX_MEMORY_SIZE] |
--virtualbox-nat-nictype "82540EM" Specify the Network Adapter Type [$VIRTUALBOX_NAT_NICTYPE] | --virtualbox-nat-nictype "82540EM" Specify the Network Adapter Type [$VIRTUALBOX_NAT_NICTYPE] |
--virtualbox-no-dns-proxy Disable proxying all DNS requests to the host [$VIRTUALBOX_NO_DNS_PROXY] | --virtualbox-no-dns-proxy Disable proxying all DNS requests to the host [$VIRTUALBOX_NO_DNS_PROXY] |
--virtualbox-no-share Disable the mount of your home directory [$VIRTUALBOX_NO_SHARE] | --virtualbox-no-share Disable the mount of your home directory [$VIRTUALBOX_NO_SHARE] |
--virtualbox-no-vtx-check Disable checking for the availability of hardware virtualization before the vm is started [$VIRTUALBOX_NO_VTX_CHECK] | --virtualbox-no-vtx-check Disable checking for the availability of hardware virtualization before the vm is started [$VIRTUALBOX_NO_VTX_CHECK] |
--virtualbox-share-folder Mount the specified directory instead of the default home location. Format: dir:name [$VIRTUALBOX_SHARE_FOLDER] | --virtualbox-share-folder Mount the specified directory instead of the default home location. Format: dir:name [$VIRTUALBOX_SHARE_FOLDER] |
--virtualbox-ui-type "headless" Specify the UI Type: (gui|sdl|headless|separate) [$VIRTUALBOX_UI_TYPE] | --virtualbox-ui-type "headless" Specify the UI Type: (gui|sdl|headless|separate) [$VIRTUALBOX_UI_TYPE] |
</code> | </code> |
| |
Now create 5 workers - **worker1** through **worker5** : | Créez maintenant 5 travailleurs - **worker1** jusqu'à **worker5** : |
| |
<code> | <code> |
</code> | </code> |
| |
====2.3 - Listing Docker VMs==== | ====2.3 - Lister les VM Docker==== |
| |
To list Docker VMs and their states, use the **ls** subcommand of the **docker-machine** command: | Pour lister les VM Docker ainsi que leurs états, il convient d'utilise la sous-commande **ls** de la commande **docker-machine** : |
| |
<code> | <code> |
</code> | </code> |
| |
====2.4 - Obtaining the IP address of VMs==== | ====2.4 - Obtenir l'adresse IP des VM==== |
| |
Another way of obtaining the IP addresses of the VMs is to use the **ip** subcommand: | Une autre façon d'obtenir les adresses IP des VM est d'utiliser la sous-commande **ip** : |
| |
<code> | <code> |
</code> | </code> |
| |
====2.5 - Connecting to a Docker VM==== | ====2.5 - Se connecter à une VM Docker==== |
| |
To connect to a Docker Machine VM, use the **ssh** subcommand of the **docker-machine** command: | Pour se connecter à une VM Docker, il convient d'utiliser la sous-commande **ssh** de la commande **docker-machine** : |
| |
<code> | <code> |
root@debian11:~# docker-machine ssh manager1 | root@debian11:~# docker-machine ssh manager1 |
( '>') | ( '>') |
/) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. | /) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. |
(/-_--_-\) www.tinycorelinux.net | (/-_--_-\) www.tinycorelinux.net |
| |
docker@manager1:~$ exit | docker@manager1:~$ exit |
| |
<WRAP center round important 50%> | <WRAP center round important 50%> |
**Important** - Note that the VM distribution is **[[http://boot2docker.io/|Boot2Docker]]**. This distribution is based on **[[http://tinycorelinux.net/|Tiny Core Linux]]**, runs entirely in RAM, weighs 27MB and boots in approximately 5 seconds. | **Important** - Notez que la distribution de la VM est **[[http://boot2docker.io/|Boot2Docker]]**. Cette distribution est basée sur **[[http://tinycorelinux.net/|Tiny Core Linux]]**, s'exécute entièrement dans la mémoire vive, pèse 27 Mo et démarre en approximativement 5 secondes. |
</WRAP> | </WRAP> |
| |
Now install the **mlocate** package: | Installez maintenant le paquet **mlocate** : |
| |
<code> | <code> |
</code> | </code> |
| |
Having been created by root, Docker Machine VMs and their associated files are stored in the **/root/.docker/machine/machines/** directory : | Ayant été créées par root, les VM Docker ainsi que leurs fichiers associés sont stockés dans le répertoire **/root/.docker/machine/machines/** : |
| |
<code> | <code> |
/root/.docker/machine/machines/manager1 | /root/.docker/machine/machines/manager1 |
/root/.docker/machine/machines/manager1/boot2docker.iso | /root/.docker/machine/machines/manager1/boot2docker.iso |
/root/.docker/machines/manager1/ca.pem | /root/.docker/machine/machines/manager1/ca.pem |
/root/.docker/machine/machines/manager1/cert.pem | /root/.docker/machine/machines/manager1/cert.pem |
/root/.docker/machine/machines/manager1/config.json | /root/.docker/machine/machines/manager1/config.json |
/root/.docker/machine/machines/manager1/manager1/Logs | /root/.docker/machine/machines/manager1/manager1/Logs |
/root/.docker/machine/machines/manager1/manager1/manager1.vbox | /root/.docker/machine/machines/manager1/manager1/manager1.vbox |
/root/.docker/machines/manager1/manager1/manager1.vbox-prev | /root/.docker/machine/machines/manager1/manager1/manager1.vbox-prev |
/root/.docker/machine/machines/manager1/manager1/Logs/VBox.log | /root/.docker/machine/machines/manager1/manager1/Logs/VBox.log |
</code> | </code> |
=====LAB #3 - Docker Swarm===== | =====LAB #3 - Docker Swarm===== |
| |
====3.1 - Overview==== | ====3.1 - Présentation==== |
| |
Docker Swarm is a utility that allows you to manage a cluster to deploy containers by enabling an imitation of docker behaviour on a single machine. | Docker Swarm est un utilitaire qui permet de gérer un cluster pour déployer des conteneurs en permettant une imitation du comportement de docker sur une seule machine. |
| |
====3.2 - Initializing Docker Swarm==== | ====3.2 - Initialiser Docker Swarm==== |
| |
To initialise Docker swarm, use the **docker swarm init** command from the Docker VM **manager1**, specifying the IP address of manager1: | Pour initialiser Docker swarm, il convient d'utiliser la commande **docker swarm init** à partir de la VM Docker **manager1** en stipulant l'adresse IP de manager1 : |
| |
<code> | <code> |
root@debian11:~# docker-machine ssh manager1 | root@debian11:~# docker-machine ssh manager1 |
( '>') | ( '>') |
/) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. | /) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. |
(/-_--_-\) www.tinycorelinux.net | (/-_--_-\) www.tinycorelinux.net |
| |
docker@manager1:~$ docker swarm init --advertise-addr 192.168.99.100 | docker@manager1:~$ docker swarm init --advertise-addr 192.168.99.100 |
</code> | </code> |
| |
Note that the following ports must be open on a manager node: 22/tcp, 2376/tcp, 2377/tcp, 7946/tcp, 7946/udp and 4789/udp. | Notez que les ports suivants doivent être ouverts sur un nœud manager : 22/tcp, 2376/tcp, 2377/tcp, 7946/tcp, 7946/udp et 4789/udp. |
| |
====3.3 - Leader status==== | ====3.3 - Le Statut Leader==== |
| |
View the status of the Docker manager1 VM: | Consultez le statut de la VM Docker manager1 : |
| |
<code> | <code> |
</code> | </code> |
| |
At any given time there can only be one **Leader**. It is possible to create other manager nodes by joining them to swarm using the token provided for this purpose. However, these management nodes remain on standby for any failure of the current Leader. | A un instant t il ne peut y avoir q'un seul **Leader**. Il est possible de créer d'autres nœuds de gestion en le rejoignant à swarm en utilisant le token prévu à cet effet. Par contre ces nœuds de gestion restent en attente d'une éventuelle défaillance du Leader actuel. |
| |
To find out the token required to join swarm as a management node, enter the following command: | Pour connaître le token nécessaire pour rejoindre swarm en tant que nœud de gestion, saisissez la commande suivante : |
| |
<code> | <code> |
</code> | </code> |
| |
====3.4 - Join the Swarm==== | ====3.4 - Rejoindre le Swarm==== |
| |
Join the 5 swarm worker machines using the **worker** token : | Rejoignez les 5 machines travailleurs à swarm en utilisant le token **worker** : |
| |
<code> | <code> |
root@debian11:~# docker-machine ssh worker1 | root@debian11:~# docker-machine ssh worker1 |
( '>') | ( '>') |
/) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. | /) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. |
(/-_--_-\) www.tinycorelinux.net | (/-_--_-\) www.tinycorelinux.net |
| |
docker@worker1:~$ docker swarm join --token SWMTKN-1-25tbmsyx452cuhpiedymuc8n9llo9jbjcbza93npdo35q1aaff-9teuxcpe09xw7v7xz1tnwpw4g 192.168.99.100:2377 | docker@worker1:~$ docker swarm join --token SWMTKN-1-25tbmsyx452cuhpiedymuc8n9llo9jbjcbza93npdo35q1aaff-9teuxcpe09xw7v7xz1tnwpw4g 192.168.99.100:2377 |
root@debian11:~# docker-machine ssh worker2 | root@debian11:~# docker-machine ssh worker2 |
( '>') | ( '>') |
/) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. | /) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. |
(/-_--_-\) www.tinycorelinux.net | (/-_--_-\) www.tinycorelinux.net |
| |
docker@worker2:~$ docker swarm join --token SWMTKN-1-25tbmsyx452cuhpiedymuc8n9llo9jbjcbza93npdo35q1aaff-9teuxcpe09xw7v7xz1tnwpw4g 192.168.99.100:2377 | docker@worker2:~$ docker swarm join --token SWMTKN-1-25tbmsyx452cuhpiedymuc8n9llo9jbjcbza93npdo35q1aaff-9teuxcpe09xw7v7xz1tnwpw4g 192.168.99.100:2377 |
root@debian11:~# docker-machine ssh worker3 | root@debian11:~# docker-machine ssh worker3 |
( '>') | ( '>') |
/) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. | /) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. |
(/-_--_-\) www.tinycorelinux.net | (/-_--_-\) www.tinycorelinux.net |
| |
docker@worker3:~$ docker swarm join --token SWMTKN-1-25tbmsyx452cuhpiedymuc8n9llo9jbjcbza93npdo35q1aaff-9teuxcpe09xw7v7xz1tnwpw4g 192.168.99.100:2377 | docker@worker3:~$ docker swarm join --token SWMTKN-1-25tbmsyx452cuhpiedymuc8n9llo9jbjcbza93npdo35q1aaff-9teuxcpe09xw7v7xz1tnwpw4g 192.168.99.100:2377 |
root@debian11:~# docker-machine ssh worker4 | root@debian11:~# docker-machine ssh worker4 |
( '>') | ( '>') |
/) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. | /) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. |
(/-_--_-\) www.tinycorelinux.net | (/-_--_-\) www.tinycorelinux.net |
| |
docker@worker4:~$ docker swarm join --token SWMTKN-1-25tbmsyx452cuhpiedymuc8n9llo9jbjcbza93npdo35q1aaff-9teuxcpe09xw7v7xz1tnwpw4g 192.168.99.100:2377 | docker@worker4:~$ docker swarm join --token SWMTKN-1-25tbmsyx452cuhpiedymuc8n9llo9jbjcbza93npdo35q1aaff-9teuxcpe09xw7v7xz1tnwpw4g 192.168.99.100:2377 |
root@debian11:~# docker-machine ssh worker5 | root@debian11:~# docker-machine ssh worker5 |
( '>') | ( '>') |
/) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. | /) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. |
(/-_--_-\) www.tinycorelinux.net | (/-_--_-\) www.tinycorelinux.net |
| |
docker@worker5:~$ docker swarm join --token SWMTKN-1-25tbmsyx452cuhpiedymuc8n9llo9jbjcbza93npdo35q1aaff-9teuxcpe09xw7v7xz1tnwpw4g 192.168.99.100:2377 | docker@worker5:~$ docker swarm join --token SWMTKN-1-25tbmsyx452cuhpiedymuc8n9llo9jbjcbza93npdo35q1aaff-9teuxcpe09xw7v7xz1tnwpw4g 192.168.99.100:2377 |
</code> | </code> |
| |
Note that the following ports must be open on a worker node: 22/tcp, 2376/tcp, 7946/tcp, 7946/udp and 4789/udp. | Notez que les ports suivants doivent être ouverts sur un nœud worker : 22/tcp, 2376/tcp, 7946/tcp, 7946/udp et 4789/udp. |
| |
The status of Docker VMs can be viewed by using the **docker node ls** command again: | L'état des VM Docker peut être consulter en utilisant de nouveau la commande **docker node ls** : |
| |
<code> | <code> |
</code> | </code> |
| |
Note that you cannot use this command from a worker: | Notez que vous ne pouvez pas utiliser cette commande à partir d'un travailleur : |
| |
<code> | <code> |
root@debian11:~# docker-machine ssh worker5 | root@debian11:~# docker-machine ssh worker5 |
( '>') | ( '>') |
/) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. | /) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. |
(/-_--_-\) www.tinycorelinux.net | (/-_--_-\) www.tinycorelinux.net |
| |
docker@worker5:~$ docker node ls | docker@worker5:~$ docker node ls |
</code> | </code> |
| |
====3.5 - Viewing Swarm==== Information | ====3.5 - Consulter les Informations de Swarm==== |
| |
It is possible to view information about the swarm using the **docker info** command: | Il est possible de visualiser les informations concernant le swarm en utilisant la commande **docker info** : |
| |
<code> | <code> |
root@debian11:~# docker-machine ssh manager1 | root@debian11:~# docker-machine ssh manager1 |
( '>') | ( '>') |
/) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. | /) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. |
(/-_--_-\) www.tinycorelinux.net | (/-_--_-\) www.tinycorelinux.net |
| |
docker@manager1:~$ docker info | docker@manager1:~$ docker info |
| |
<WRAP center round important 50%> | <WRAP center round important 50%> |
**Important** - When the Docker Engine is in swarm mode, management nodes implement the **[[https://docs.docker.com/engine/swarm/raft/|Raft Consensus Algorithm]]** to manage cluster state. | **Important** - Quand le moteur Docker est en mode swarm, les noeuds de gestion implémentent le **[[https://docs.docker.com/engine/swarm/raft/|Raft Consensus Algorithm]]** pour gérer l'état du cluster. |
</WRAP> | </WRAP> |
| |
====3.6 - Starting a Service==== | ====3.6 - Démarrer un Service==== |
| |
In this example, we will start the **nginx** service with the following properties: | Dans cet exemple, nous allons démarrer le service **nginx** avec les propriétés suivantes : |
| |
* Mapping the nginx port to port 80 on the host machine, | * Mappage du port nginx sur le port 80 de la machine hôte, |
* 5 instances of the service, | * 5 instances du service, |
* A unique name of **web**. | * Un nom unique de **web**. |
| |
<code> | <code> |
oree977o1unlk5ndos0y44i2h | oree977o1unlk5ndos0y44i2h |
overall progress: 5 out of 5 tasks | overall progress: 5 out of 5 tasks |
1/5: running [==================================================>] | 1/5: running [==================================================>] |
2/5: running [==================================================>] | 2/5: running [==================================================>] |
3/5: running [==================================================>] | 3/5: running [==================================================>] |
4/5: running [==================================================>] | 4/5: running [==================================================>] |
5/5: running [==================================================>] | 5/5: running [==================================================>] |
verify: Service converged | verify: Service converged |
</code> | </code> |
| |
To check the status of this service, use the **docker service ls** command : | Pour consulter l'état de ce service, utilisez la commande **docker service ls** : |
| |
<code> | <code> |
</code> | </code> |
| |
This service runs in Docker containers: | Ce service fonctionne dans des conteneurs Docker : |
| |
<code> | <code> |
| |
<WRAP center round important 50%> | <WRAP center round important 50%> |
**Important** - Note that there is no container on worker1. | **Important** - Notez qu'il n'y a pas de conteneur sur worker1. |
</WRAP> | </WRAP> |
| |
To see that the nginx daemon has been launched, run the **docker ps** command on the **manager1** machine: | Pour constater le lancement du daemon nginx, lancez la commande **docker ps** sur la machine **manager1** : |
| |
<code> | <code> |
</code> | </code> |
| |
On the other hand, the same command executed on **worker1** gives the following result: | Par contre la même commande exécutée sur **worker1** donne le résultat suivant : |
| |
<code> | <code> |
root@debian11:~# docker-machine ssh worker1 | root@debian11:~# docker-machine ssh worker1 |
( '>') | ( '>') |
/) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. | /) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. |
(/-_--_-\) www.tinycorelinux.net | (/-_--_-\) www.tinycorelinux.net |
| |
docker@worker1:~$ docker ps | docker@worker1:~$ docker ps |
</code> | </code> |
| |
Connect to each Docker Machine VM to see that the nginx service is accessible: | Connectez-vous sur chaque VM Docker pour constater que le service nginx fonctionne : |
| |
<code> | <code> |
root@debian11:~# docker-machine ssh manager1 | root@debian11:~# docker-machine ssh manager1 |
( '>') | ( '>') |
/) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. | /) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. |
(/-_--_-\) www.tinycorelinux.net | (/-_--_-\) www.tinycorelinux.net |
| |
docker@manager1:~$ curl 192.168.99.100 | docker@manager1:~$ curl 192.168.99.100 |
<html> | <html> |
<head> | <head> |
<title>Welcome to nginx</title> | <title>Welcome to nginx!</title> |
<style> | <style> |
html { color-scheme: light dark; } | html { color-scheme: light dark; } |
</head> | </head> |
<body> | <body> |
<h1>Welcome to nginx</h1> | <h1>Welcome to nginx!</h1> |
<p>If you see this page, the nginx web server is successfully installed and | <p>If you see this page, the nginx web server is successfully installed and |
working. Further configuration is required.</p> | working. Further configuration is required.</p> |
| |
<For online documentation and support please refer to | <p>For online documentation and support please refer to |
<a href="http://nginx.org/">nginx.org</a>.<br/> | <a href="http://nginx.org/">nginx.org</a>.<br/> |
Commercial support is available at | Commercial support is available at |
<html> | <html> |
<head> | <head> |
<title>Welcome to nginx</title> | <title>Welcome to nginx!</title> |
<style> | <style> |
html { color-scheme: light dark; } | html { color-scheme: light dark; } |
</head> | </head> |
<body> | <body> |
<h1>Welcome to nginx</h1> | <h1>Welcome to nginx!</h1> |
<p>If you see this page, the nginx web server is successfully installed and | <p>If you see this page, the nginx web server is successfully installed and |
working. Further configuration is required.</p> | working. Further configuration is required.</p> |
| |
<For online documentation and support please refer to | <p>For online documentation and support please refer to |
<a href="http://nginx.org/">nginx.org</a>.<br/> | <a href="http://nginx.org/">nginx.org</a>.<br/> |
Commercial support is available at | Commercial support is available at |
<html> | <html> |
<head> | <head> |
<title>Welcome to nginx</title> | <title>Welcome to nginx!</title> |
<style> | <style> |
html { color-scheme: light dark; } | html { color-scheme: light dark; } |
</head> | </head> |
<body> | <body> |
<h1>Welcome to nginx</h1> | <h1>Welcome to nginx!</h1> |
<p>If you see this page, the nginx web server is successfully installed and | <p>If you see this page, the nginx web server is successfully installed and |
working. Further configuration is required.</p> | working. Further configuration is required.</p> |
| |
<For online documentation and support please refer to | <p>For online documentation and support please refer to |
<a href="http://nginx.org/">nginx.org</a>.<br/> | <a href="http://nginx.org/">nginx.org</a>.<br/> |
Commercial support is available at | Commercial support is available at |
<html> | <html> |
<head> | <head> |
<title>Welcome to nginx</title> | <title>Welcome to nginx!</title> |
<style> | <style> |
html { color-scheme: light dark; } | html { color-scheme: light dark; } |
</head> | </head> |
<body> | <body> |
<h1>Welcome to nginx</h1> | <h1>Welcome to nginx!</h1> |
<p>If you see this page, the nginx web server is successfully installed and | <p>If you see this page, the nginx web server is successfully installed and |
working. Further configuration is required.</p> | working. Further configuration is required.</p> |
| |
<For online documentation and support please refer to | <p>For online documentation and support please refer to |
<a href="http://nginx.org/">nginx.org</a>.<br/> | <a href="http://nginx.org/">nginx.org</a>.<br/> |
Commercial support is available at | Commercial support is available at |
<html> | <html> |
<head> | <head> |
<title>Welcome to nginx</title> | <title>Welcome to nginx!</title> |
<style> | <style> |
html { color-scheme: light dark; } | html { color-scheme: light dark; } |
</head> | </head> |
<body> | <body> |
<h1>Welcome to nginx</h1> | <h1>Welcome to nginx!</h1> |
<p>If you see this page, the nginx web server is successfully installed and | <p>If you see this page, the nginx web server is successfully installed and |
working. Further configuration is required.</p> | working. Further configuration is required.</p> |
| |
<For online documentation and support please refer to | <p>For online documentation and support please refer to |
<a href="http://nginx.org/">nginx.org</a>.<br/> | <a href="http://nginx.org/">nginx.org</a>.<br/> |
Commercial support is available at | Commercial support is available at |
<html> | <html> |
<head> | <head> |
<title>Welcome to nginx</title> | <title>Welcome to nginx!</title> |
<style> | <style> |
html { color-scheme: light dark; } | html { color-scheme: light dark; } |
</head> | </head> |
<body> | <body> |
<h1>Welcome to nginx</h1> | <h1>Welcome to nginx!</h1> |
<p>If you see this page, the nginx web server is successfully installed and | <p>If you see this page, the nginx web server is successfully installed and |
working. Further configuration is required.</p> | working. Further configuration is required.</p> |
| |
<For online documentation and support please refer to | <p>For online documentation and support please refer to |
<a href="http://nginx.org/">nginx.org</a>.<br/> | <a href="http://nginx.org/">nginx.org</a>.<br/> |
Commercial support is available at | Commercial support is available at |
| |
<WRAP center round important 50%> | <WRAP center round important 50%> |
**Important** - Note that the service is even available on worker1. | **Important** - Notez que le service est même disponible en consultant l'adresse IP de worker1. |
</WRAP> | </WRAP> |
| |
====3.7 - Scaling Up and Scaling Down the Service==== | ====3.7 - Augmentation et Réduction du Service==== |
| |
Currently, there are 5 containers running. To scale up to 8 containers, the **docker service scale** command should be used: | Actuellement, il existe 5 conteneurs en cours d'exécution. Pour procéder à un scale-up à 8 conteneurs, il convient d'utiliser la commande **docker service scale** : |
| |
<code> | <code> |
web scaled to 8 | web scaled to 8 |
overall progress: 8 out of 8 tasks | overall progress: 8 out of 8 tasks |
1/8: running [==================================================>] | 1/8: running [==================================================>] |
2/8: running [==================================================>] | 2/8: running [==================================================>] |
3/8: running [==================================================>] | 3/8: running [==================================================>] |
4/8: running [==================================================>] | 4/8: running [==================================================>] |
5/8: running [==================================================>] | 5/8: running [==================================================>] |
6/8: running [==================================================>] | 6/8: running [==================================================>] |
7/8: running [==================================================>] | 7/8: running [==================================================>] |
8/8: running [==================================================>] | 8/8: running [==================================================>] |
verify: Service converged | verify: Service converged |
</code> | </code> |
| |
Note that the **docker service ls** command confirms the fact that there are 8 replicas : | Notez que la commande **docker service ls** confirme le fait qu'il y a 8 replicas : |
| |
<code> | <code> |
</code> | </code> |
| |
Of the three additional replicas, two were run on worker5 while the third was run on worker1 : | Des trois replicas supplémentaires, deux ont été lancés sur worker5 tandis que le troisième a été lancé sur worker1 : |
| |
<code> | <code> |
pui4dnkepu27 web.6 nginx:latest worker1 Running Running about a minute ago | pui4dnkepu27 web.6 nginx:latest worker1 Running Running about a minute ago |
yj0kexdcuo5u web.7 nginx:latest worker5 Running Running about a minute ago | yj0kexdcuo5u web.7 nginx:latest worker5 Running Running about a minute ago |
93jtbxqj2dyz web.8 nginx:latest worker1 Running Running about a minute ago | 93jtbxqj2dyz web.8 nginx:latest worker1 Running Running about a minute ago |
</code> | </code> |
| |
====3.8 - Checking the status of a node==== | ====3.8 - Consulter le Statut d'un Noeud==== |
| |
To find out the status of the current node, use the **docker node inspect** command with the **self** keyword: | Pour se renseigner sur le statut du nœud courant, il convient d'utiliser la commande **docker node inspect** avec le mot clef **self** : |
| |
<code> | <code> |
"ID": "y0war0lijmwhnexrfhfflulsd", | "ID": "y0war0lijmwhnexrfhfflulsd", |
"Version": { | "Version": { |
{ "Index": 9 | "Index": 9 |
}, | }, |
"CreatedAt": "2023-12-16T13:38:18.600836601Z", | "CreatedAt": "2023-12-16T13:38:18.600836601Z", |
}, | }, |
"TLSInfo": { | "TLSInfo": { |
"TrustRoot": "-----BEGIN CERTIFICATE----- \nMIIBazCCARCgAwIBAgIUbi2tpJHqoqK+BA/p9c+Y9AmtQSAwCgYIKoZIzj0EAwIw\nEzERMA8GA1UEAxMIc3dhcm0tY2EwHhcNMjMxMjE2MTMzMzAwWhcNNDMxMjExMTMz\nMzAwWjATMREwDwYDVQQDEwhzd2FybS1jYTBZMBMGByqGSM49AgEGCCqGSM49AwEH\nA0IABKuD7Svum+bER9CszNtFt7ASMr5gj6Vea0oM7SCrlyYMCn8ryaHXQ9J+iEIh\nfWrpKmjNtei3/j+leOVF0flpg2OjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMB\nAf8EBTADAQH/MB0GA1UdDgQWBBRqlCTTUy9JODtzaVecgmjID/M5kzAKBggqhkjO\nPQQDAgNJADBGAiEA06sGunqGwd23lyjcUoczMWGQGln9nv0pmm/riJQvB80CIQC9\nvXNZUbC6U5lSQ7eGhfmmHi1JAfb88wGau0AlreBczw==\n- ----END CERTIFICATE-----\n", | "TrustRoot": "-----BEGIN CERTIFICATE-----\nMIIBazCCARCgAwIBAgIUbi2tpJHqoqK+BA/p9c+Y9AmtQSAwCgYIKoZIzj0EAwIw\nEzERMA8GA1UEAxMIc3dhcm0tY2EwHhcNMjMxMjE2MTMzMzAwWhcNNDMxMjExMTMz\nMzAwWjATMREwDwYDVQQDEwhzd2FybS1jYTBZMBMGByqGSM49AgEGCCqGSM49AwEH\nA0IABKuD7Svum+bER9CszNtFt7ASMr5gj6Vea0oM7SCrlyYMCn8ryaHXQ9J+iEIh\nfWrpKmjNtei3/j+leOVF0flpg2OjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMB\nAf8EBTADAQH/MB0GA1UdDgQWBBRqlCTTUy9JODtzaVecgmjID/M5kzAKBggqhkjO\nPQQDAgNJADBGAiEA06sGunqGwd23lyjcUoczMWGQGln9nv0pmm/riJQvB80CIQC9\nvXNZUbC6U5lSQ7eGhfmmHi1JAfb88wGau0AlreBczw==\n-----END CERTIFICATE-----\n", |
"CertIssuerSubject": "MBMxETAPBgNVBAMTCHN3YXJtLWNh", | "CertIssuerSubject": "MBMxETAPBgNVBAMTCHN3YXJtLWNh", |
"CertIssuerPublicKey": "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEq4PtK+6b5sRH0KzM20W3sBIyvmCPpV5rSgztIKuXJgwKfyvJoddD0n6IQiF9aukqaM216Lf+P6V45UXR+WmDYw==" | "CertIssuerPublicKey": "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEq4PtK+6b5sRH0KzM20W3sBIyvmCPpV5rSgztIKuXJgwKfyvJoddD0n6IQiF9aukqaM216Lf+P6V45UXR+WmDYw==" |
</code> | </code> |
| |
To find out about the status of another node, use the **docker node inspect** command with the name of the node concerned: | Pour se renseigner sur le statut d'un autre nœud, il convient d'utiliser la commande **docker node inspect** avec le nom du nœud concerné : |
| |
<code> | <code> |
"ID": "v5ai62lmhfsdcauccqmjyu6qk", | "ID": "v5ai62lmhfsdcauccqmjyu6qk", |
"Version": { | "Version": { |
{ "Index": 15 | "Index": 15 |
}, | }, |
"CreatedAt": "2023-12-16T13:40:08.301827885Z", | "CreatedAt": "2023-12-16T13:40:08.301827885Z", |
}, | }, |
"TLSInfo": { | "TLSInfo": { |
"TrustRoot": "-----BEGIN CERTIFICATE----- \nMIIBazCCARCgAwIBAgIUbi2tpJHqoqK+BA/p9c+Y9AmtQSAwCgYIKoZIzj0EAwIw\nEzERMA8GA1UEAxMIc3dhcm0tY2EwHhcNMjMxMjE2MTMzMzAwWhcNNDMxMjExMTMz\nMzAwWjATMREwDwYDVQQDEwhzd2FybS1jYTBZMBMGByqGSM49AgEGCCqGSM49AwEH\nA0IABKuD7Svum+bER9CszNtFt7ASMr5gj6Vea0oM7SCrlyYMCn8ryaHXQ9J+iEIh\nfWrpKmjNtei3/j+leOVF0flpg2OjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMB\nAf8EBTADAQH/MB0GA1UdDgQWBBRqlCTTUy9JODtzaVecgmjID/M5kzAKBggqhkjO\nPQQDAgNJADBGAiEA06sGunqGwd23lyjcUoczMWGQGln9nv0pmm/riJQvB80CIQC9\nvXNZUbC6U5lSQ7eGhfmmHi1JAfb88wGau0AlreBczw==\n- ----END CERTIFICATE-----\n", | "TrustRoot": "-----BEGIN CERTIFICATE-----\nMIIBazCCARCgAwIBAgIUbi2tpJHqoqK+BA/p9c+Y9AmtQSAwCgYIKoZIzj0EAwIw\nEzERMA8GA1UEAxMIc3dhcm0tY2EwHhcNMjMxMjE2MTMzMzAwWhcNNDMxMjExMTMz\nMzAwWjATMREwDwYDVQQDEwhzd2FybS1jYTBZMBMGByqGSM49AgEGCCqGSM49AwEH\nA0IABKuD7Svum+bER9CszNtFt7ASMr5gj6Vea0oM7SCrlyYMCn8ryaHXQ9J+iEIh\nfWrpKmjNtei3/j+leOVF0flpg2OjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMB\nAf8EBTADAQH/MB0GA1UdDgQWBBRqlCTTUy9JODtzaVecgmjID/M5kzAKBggqhkjO\nPQQDAgNJADBGAiEA06sGunqGwd23lyjcUoczMWGQGln9nv0pmm/riJQvB80CIQC9\nvXNZUbC6U5lSQ7eGhfmmHi1JAfb88wGau0AlreBczw==\n-----END CERTIFICATE-----\n", |
"CertIssuerSubject": "MBMxETAPBgNVBAMTCHN3YXJtLWNh", | "CertIssuerSubject": "MBMxETAPBgNVBAMTCHN3YXJtLWNh", |
"CertIssuerPublicKey": "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEq4PtK+6b5sRH0KzM20W3sBIyvmCPpV5rSgztIKuXJgwKfyvJoddD0n6IQiF9aukqaM216Lf+P6V45UXR+WmDYw==" | "CertIssuerPublicKey": "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEq4PtK+6b5sRH0KzM20W3sBIyvmCPpV5rSgztIKuXJgwKfyvJoddD0n6IQiF9aukqaM216Lf+P6V45UXR+WmDYw==" |
</code> | </code> |
| |
The **--pretty** option produces more easily readable output: | L'option **--pretty** produit une sortie plus facilement lisible : |
| |
<code> | <code> |
</code> | </code> |
| |
====3.9 - High Availability==== | ====3.9 - Haute Disponibilité==== |
| |
When a node is active, it is able to receive new tasks from the manager: | Quand un nœud est actif, il est capable de recevoir de nouvelles tâches à partir du manager : |
| |
* during a scale-up, | * pendant un scale-up, |
* during a progressive upgrade, | * pendant une une mise à jour progressive, |
* when another node receives an instruction to be unavailable, | * quand un autre nœud reçois une instruction de se mettre en indisponibilité, |
* when a service fails on another node. | * quand un service se mets en échec sur un autre nœud |
| |
Remember that the swarm contains 6 Docker VMs: | Rappelez-vous que la swarm contient 6 VM Docker : |
| |
<code> | <code> |
</code> | </code> |
| |
And that out of the 6 Docker VMs, there are 8 containers, | et que sur les 6 VM Docker, il y a 8 conteneurs, |
| |
<code> | <code> |
</code> | </code> |
| |
two of which are on worker1: | dont deux se trouvent sur worker1 : |
| |
<code> | <code> |
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS | ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS |
pui4dnkepu27 web.6 nginx:latest worker1 Running Running 4 minutes ago | pui4dnkepu27 web.6 nginx:latest worker1 Running Running 4 minutes ago |
93jtbxqj2dyz web.8 nginx:latest worker1 Running Running 4 minutes ago | 93jtbxqj2dyz web.8 nginx:latest worker1 Running Running 4 minutes ago |
</code> | </code> |
| |
Put worker1 into unavailability mode using the **--availability drain** option: | Mettez worker1 en mode d'indisponibilité en utilisant l'option **--availability drain** : |
| |
<code> | <code> |
</code> | </code> |
| |
Notice that the web service has been moved to two other nodes, **manager1** and **worker4** : | Constatez que le service web a été déplacé sur deux autres noeuds, **manager1** et **worker4** : |
| |
<code> | <code> |
yj0kexdcuo5u web.7 nginx:latest worker5 Running Running 5 minutes ago | yj0kexdcuo5u web.7 nginx:latest worker5 Running Running 5 minutes ago |
kv7ax6cwzpkf web.8 nginx:latest worker2 Running Running 3 seconds ago | kv7ax6cwzpkf web.8 nginx:latest worker2 Running Running 3 seconds ago |
93jtbxqj2dyz \_ web.8 nginx:latest worker1 Shutdown Shutdown 4 seconds ago | 93jtbxqj2dyz \_ web.8 nginx:latest worker1 Shutdown Shutdown 4 seconds ago |
</code> | </code> |
| |
====3.10 - Removing a Service=== | ====3.10 - Supprimer un Service=== |
| |
To remove a service you should use the **docker service rm** command. | Pour supprimer un service il convient d'utiliser la commande **docker service rm** |
| |
<code> | <code> |
</code> | </code> |
| |
====3.11 - Backing up Docker Swarm==== | ====3.11 - Sauvegarder Docker Swarm==== |
| |
The Docker Swarm configuration is contained in the **/var/lib/docker/swarm** directory of each Manager in the Swarm : | La configuration de Docker Swarm est contenue dans le répertoire **/var/lib/docker/swarm** de chaque Manager dans le Swarm : |
| |
<code> | <code> |
root@manager1:~# ls -l /var/lib/docker/swarm | root@manager1:~# ls -l /var/lib/docker/swarm |
total 20 | total 20 |
drwxr-xr-x 2 root root 4096 Dec 16 13:38 certificates | drwxr-xr-x 2 root root 4096 Dec 16 13:38 certificates |
-rw------- 1 root root 215 Dec 16 13:38 docker-state.json | -rw------- 1 root root 215 Dec 16 13:38 docker-state.json |
drwx------ 4 root root 4096 Dec 16 13:38 raft | drwx------ 4 root root 4096 Dec 16 13:38 raft |
-rw------- 1 root root 70 Dec 16 13:38 state.json | -rw------- 1 root root 70 Dec 16 13:38 state.json |
drwxr-xr-x 2 root root 4096 Dec 16 13:38 worker | drwxr-xr-x 2 root root 4096 Dec 16 13:38 worker |
</code> | </code> |
| |
The backup process requires there to be at least **two** Managers in the Swarm. The backup procedure is : | Le processus de sauvegarde necéssite qu'il y ait au moins **deux** Managers dans le Swarm. Le procédure de sauvegarde est : |
| |
* stop the Docker service on the Manager to be backed up, | * arrêt du service Docker sur le Manager à sauvegarder, |
* backup the **/var/lib/docker/swarm** directory, | * sauvegarde du répertoire **/var/lib/docker/swarm**, |
* restart the Docker service on the Manager concerned. | * redémarrage du service Docker sur le Manager concerné. |
| |
====3.12 - Restoring Docker Swarm==== | ====3.12 - Restaurer Docker Swarm==== |
| |
The restore procedure is : | Le procédure de resturation est : |
| |
* stop the Docker service on a new Manager, | * arrêt du service Docker sur un nouveau Manager, |
* delete the contents of the **/var/lib/docker/swarm** directory in the new Manager, | * suppression du contenu du répertoire **/var/lib/docker/swarm** dans le nouveau Manager, |
* restore the **/var/lib/docker/swarm** directory in the new Manager from the backup, | * restauration du répertoire **/var/lib/docker/swarm** dans le nouveau Manager à partir de la sauvegarde, |
* run the **docker swarm init --force-new-cluster** command on the new Manager, | * exécution de la commande **docker swarm init --force-new-cluster** sur le nouveau Manager, |
* Add Managers and Workers to Swarm. | * ajout des Managers et Workers à Swarm. |
| |
----- | ----- |
| |
Copyright © 2023 Hugh Norris. | Copyright © 2024 Hugh Norris. |