Skip to content

Instantly share code, notes, and snippets.

@srz-zumix
Created May 19, 2022 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srz-zumix/4bd600e295ac68261811b57c6bacacde to your computer and use it in GitHub Desktop.
Save srz-zumix/4bd600e295ac68261811b57c6bacacde to your computer and use it in GitHub Desktop.
docker tags copy
#!/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