Skip to content

Instantly share code, notes, and snippets.

@steve-jansen
Last active February 11, 2021 10:44
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save steve-jansen/2de5602205fe82161112 to your computer and use it in GitHub Desktop.
Save steve-jansen/2de5602205fe82161112 to your computer and use it in GitHub Desktop.
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