-
-
Save timoyuen/2f63fc604852b4b9207b622c5f8a80e2 to your computer and use it in GitHub Desktop.
Mirror a Docker Trusted Registry (DTR) to another registry
This file contains 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 | |
read -p "Registry to clone from: " pull_registry | |
read -p "Username for $pull_registry: " user | |
read -s -p "Password for $pull_registry: " password | |
echo | |
read -p "Registry to clone onto: " push_registry | |
echo Querying $pull_registry... | |
[ -f list.txt ] && rm list.txt | |
for repo in $(curl -s -X GET \ | |
-H "Accept: application/json" \ | |
--user "$user:$password" \ | |
https://$pull_registry/api/v0/repositories | \ | |
jq -r '.repositories[] | [.namespace, .name] | join("/")') | |
do | |
for tag in $(curl -s -X GET \ | |
-H "Accept: application/json" \ | |
--user "$user:$password" \ | |
https://$pull_registry/api/v0/repositories/$repo/tags | \ | |
jq -r '.tags[] | .name') | |
do | |
echo $repo:$tag >> list.txt | |
done | |
done | |
while read slug; do | |
set -x | |
docker pull $pull_registry/$slug | |
set +x | |
done < list.txt | |
while read slug; do | |
set -x | |
docker tag $pull_registry/$slug $push_registry/$slug | |
set +x | |
done < list.txt | |
while read slug; do | |
set -x | |
docker push $push_registry/$slug | |
set +x | |
done < list.txt | |
[ -f list.txt ] && rm list.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment