Ci-dessous, les différences entre deux révisions de la page.
tutoriaux:docker-related:migrate-docker [2025/04/25 15:24] – créée frater | tutoriaux:docker-related:migrate-docker [2025/04/25 15:54] (Version actuelle) – [Restauration volumes des données] frater | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ====== Migration de conteneurs docker ====== | ||
+ | |||
+ | |||
+ | ==== Backup des volumes de données ==== | ||
+ | |||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | |||
+ | # List all Docker volumes with name containing ' | ||
+ | volumes=$(docker volume ls --filter name=volumes | awk ' | ||
+ | |||
+ | for volume in $volumes; do | ||
+ | # Exclude the " | ||
+ | if [[ " | ||
+ | # Backup the volume to a tar.gz file in the current directory | ||
+ | docker run --rm -v $volume:/ | ||
+ | fi | ||
+ | done | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
<cli> | <cli> | ||
- | frater@docker02:~/ for backup in ./*.tar.gz; do volume_name=$(basename " | + | frater@hades:~# sudo docker volume ls --filter name=peertube | awk ' |
+ | </ | ||
+ | |||
+ | ==== Restauration volumes des données ==== | ||
+ | <code bash> | ||
+ | # | ||
+ | |||
+ | # Loop through all .tar.gz files in the current directory | ||
+ | for backup in *.tar.gz; do | ||
+ | # Extract the volume name from the filename (remove the .tar.gz extension) | ||
+ | volume_name=$(basename " | ||
+ | |||
+ | # Create a Docker volume with the same name as the tar file | ||
+ | docker volume create " | ||
+ | |||
+ | # Unpack the contents of the tar.gz file into the newly created volume | ||
+ | docker run --rm -v " | ||
+ | done | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | < | ||
+ | frater@docker02: | ||
</ | </ |