Skip to content

Instantly share code, notes, and snippets.

@ethack
Created August 11, 2021 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethack/4bed4c02cfcda20c666f2cb855b60790 to your computer and use it in GitHub Desktop.
Save ethack/4bed4c02cfcda20c666f2cb855b60790 to your computer and use it in GitHub Desktop.
Transfer a docker image from one machine to another over SSH
#!/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