Created
May 19, 2022 12:17
-
-
Save srz-zumix/4bd600e295ac68261811b57c6bacacde to your computer and use it in GitHub Desktop.
docker tags copy
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
#!/bin/bash | |
# usage: docker-cp-repo.sh src_repo dst_repo | |
set -euo pipefail | |
SRC_REPO=$1 | |
DST_REPO=$2 | |
SRC_TAGS=$(curl -s https://registry.hub.docker.com/v1/repositories/${SRC_REPO}/tags | jq -r '.[].name') | |
DST_TAGS=$(curl -s https://registry.hub.docker.com/v1/repositories/${DST_REPO}/tags | jq -r '.[].name') | |
ONE_SIDE_TAGS=$(echo -e "${SRC_TAGS}\n${DST_TAGS}" | sort | uniq -u) | |
SRC_ONLY_TAGS=$(echo -e "${SRC_TAGS}\n${ONE_SIDE_TAGS}" | sort | uniq -d) | |
for t in ${SRC_ONLY_TAGS}; do | |
echo $t | |
docker pull "${SRC_REPO}:$t" | |
docker tag "${SRC_REPO}:$t" "${DST_REPO}:$t" | |
docker push "${DST_REPO}:$t" | |
done | |
deleteTags() { | |
docker images | grep "$1" | awk '{print $2}' | xargs -I{} docker rmi $1:{} | |
} | |
# deleteTags "${SRC_REPO}" | |
# deleteTags "${DST_REPO}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment