Skip to content

Instantly share code, notes, and snippets.

@JonasGao
Created April 15, 2025 11:44
Show Gist options
  • Save JonasGao/721279a09473a223b45a6dda6c7e3592 to your computer and use it in GitHub Desktop.
Save JonasGao/721279a09473a223b45a6dda6c7e3592 to your computer and use it in GitHub Desktop.
Pull target image save to private registry.
#!/bin/bash
# 用法1: proxy docker.io/library/caddy:2-alpine
# 用法2: proxy -c docker.io/library/caddy:2-alpine
# 用法3: proxy docker.io/library/caddy:2-alpine library/caddy:2-alpine
remove_domain=false
if [ "$1" = "-c" ]; then
remove_domain=true
shift
fi
[ -z "$1" ] && echo "ERROR: missing image" && exit 1
source_repo="$1"
private_reg="127.0.0.1:5000"
if [ "$remove_domain" = "true" ]; then
target_repo=$(echo "$source_repo" | sed 's/^[^/]*\///')
fi
if [ -n "$2" ]; then
target_repo="$2"
fi
target_repo="$private_reg/$target_repo"
set -xe
docker pull $source_repo
docker tag $source_repo $target_repo
docker push $target_repo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment