Do the following on the source machine where $VOLUME
is the name of the volume:
1 |
docker run --rm -v $VOLUME:/$VOLUME alpine tar -czv --to-stdout -C /$VOLUME . > $VOLUME.tgz |
This creates an alpine container that gets removed upon completion (--rm
), mounts the volume to the root location (-v $VOLUME:/$VOLUME
) then runs tar
to create an archive and output it to the STDOUT (tar -czv --to-stdout -C /$VOLUME .
) which is saved to a file on the source machine (> $VOLUME.tgz
).
Now copy this over to the destination machine:
1 |
scp $VOLUME.tgz $DEST: |
SSH onto the remote host and import thus:
1 |
cat $VOLUME.tgz | docker run --rm -i -v $VOLUME:/$VOLUME alpine tar xzf - -C /$VOLUME |
I cat
the archive to STDOUT, start another alpine container that gets removed upon completion (--rm
) and accepts from STDIN (-i
), it has the volume mapped to it (-v $VOLUME:/$VOLUME
)(and the volume is automatically created on the host if it doesn’t exist); this container is piped to the previous cat
command and runs tar to accept input from STDIN and extract to the volume mounted within the container (tar xzf - -C /$VOLUME
).
Hmm, I haven’t tried this yet but one might be able to pipe into SSH directly so perhaps I can combine these two commands:
1 |
docker run --rm -v $VOLUME:/$VOLUME alpine tar -czv --to-stdout -C /$VOLUME . | ssh $REMOTEHOST "docker run --rm -i -v $VOLUME:/$VOLUME alpine tar xzf - -C /$VOLUME" |