Created
August 11, 2021 00:12
-
-
Save ethack/4bed4c02cfcda20c666f2cb855b60790 to your computer and use it in GitHub Desktop.
Transfer a docker image from one machine to another over SSH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -eq 0 ]; then | |
cat <<EOF | |
Usage: $0 <docker image> <ssh args> | |
<docker image> the name of the image to transfer | |
<ssh args> all arguments are passed through to ssh to establish the connection | |
EOF | |
exit 1 | |
fi | |
exists () { | |
command -v $1 >/dev/null 2>&1 | |
} | |
# note: include tag to exclude all intermediate stage layers | |
# drop tag to transfer all stages and tags | |
IMAGE="$1" | |
shift | |
if exists pv && exists jq; then | |
# display nice progress bar | |
docker image save "$IMAGE" | pv --size $(docker image inspect "$IMAGE" | jq '.[].Size') | ssh -C "$@" docker image load | |
else | |
docker image save "$IMAGE" | ssh -C "$@" docker image load | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment