Created
July 21, 2025 06:36
-
-
Save lewcpe/d977fb6b69fd5f7f7176ecc63dc97afb to your computer and use it in GitHub Desktop.
Transfer docker image to remote machine without docker registry
This file contains hidden or 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
| 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