Docker Container auf anderen Host migrieren
Das funktioniert sehr gut, Container sollten vorher gestoppt werden:
docker run --rm -v <SOURCE_DATA_VOLUME_NAME>:/from alpine ash -c "cd /from ; tar -cf - . " | ssh <TARGET_HOST> 'docker run --rm -i -v <TARGET_DATA_VOLUME_NAME>:/to alpine ash -c "cd /to ; tar -xpvf - " '
The main ideas behind this one-liner are:
Run ash in alpine container and map the named data volume SOURCE_DATA_VOLUME_NAME to the directory /from in the container
Execute the command tar to tar the whole contents of the /from directory to the standard output
ssh to TARGET_HOST where we start ash in a alpine linux docker container with:
standard input redirected using -i and use the
TARGET_DATA_VOLUME_NAME data volume mapped to the /to directory
Using the tar command to untar the stream sent over ssh into the /to directory
https://www.guidodiepen.nl/2016/05/transfer-docker-data-volume-to-another-host/