Skip to content

Instantly share code, notes, and snippets.

@lewcpe
Created July 21, 2025 06:36
Show Gist options
  • Select an option

  • Save lewcpe/d977fb6b69fd5f7f7176ecc63dc97afb to your computer and use it in GitHub Desktop.

Select an option

Save lewcpe/d977fb6b69fd5f7f7176ecc63dc97afb to your computer and use it in GitHub Desktop.
Transfer docker image to remote machine without docker registry
dcp() {
if [ "$#" -ne 2 ]; then
echo "Usage: dcp <image:tag> <user@host>"
return 1
fi
# Check if pv is installed
if ! command -v pv &> /dev/null; then
echo "❌ Error: 'pv' is not installed. Please install it to show progress."
return 1
fi
local image="$1"
local dest="$2"
local image_size
# Get the image's uncompressed size to provide an accurate progress bar
image_size=$(docker image inspect --format='{{.Size}}' "$image")
if [ -z "$image_size" ]; then
echo "❌ Error: Could not determine size of image '$image'. Aborting."
return 1
fi
echo "πŸš€ Transferring image '$image' to '$dest'..."
docker save "$image" | pv -s "$image_size" | gzip | ssh "$dest" "gunzip | docker load"
echo "βœ… Transfer complete."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment