Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mirror a Docker Trusted Registry (DTR) to another registry
#!/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