Skip to content

Instantly share code, notes, and snippets.

@caruccio
Last active October 14, 2024 15:52
Show Gist options
  • Save caruccio/3b75b74bbe7249a1ce7eb0bb5b90aa64 to your computer and use it in GitHub Desktop.
Save caruccio/3b75b74bbe7249a1ce7eb0bb5b90aa64 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ $# -lt 2 ]; then
echo Usage: $0 NEW-REGISTRY NEW-OWNER [push]
exit 1
fi
new_registry="$1"
new_owner="$2"
push="$3"
docker images --format '{{.Repository}}:{{.Tag}}' \
| grep -E '^(docker.io|quay.io|ghcr.io|k8s.gcr.io)/' \
| grep -v ':<none>$' \
| sort -u \
| while read image; do
# registry/image:tag
image_name=${image#*/}
image_name=${image_name%:*}
image_tag=${image##*:}
if [[ $image =~ [^/]+/[^/]+/[^/]+:.* ]]; then
# registry/owner/image:tag
image_name=${image_name%/*}_${image_name#*/}
fi
new_image=$new_registry/$new_owner/$image_name:$image_tag
if [ "$push" == push ]; then
docker tag $image $new_image
docker push $new_image
else
echo docker tag $image $new_image
echo docker push $new_image
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment