Copying a docker volume from one host to another

Do the following on the source machine where $VOLUME is the name of the volume:

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:

SSH onto the remote host and import thus:

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: