Created
February 25, 2021 19:45
-
-
Save ferferga/60e9ddfaaae37bb6826a53cbc930f305 to your computer and use it in GitHub Desktop.
Copy all the images and tags from an user in DockerHub to ghcr.io
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 | |
# Simple script to repush docker images from one repository to another | |
username="ferferga" | |
# Github package registry. You need to be logged in first | |
target_repo="ghcr.io" | |
img_file="image_list.txt" | |
tag_file="tag_list.txt" | |
rm -rf $img_file | |
wget -q https://hub.docker.com/v2/repositories/$username/ -O - | jq -r '.results[] | . | .namespace + "/" + .name' >> $img_file | |
while read -r line; do | |
original_image="$line" | |
new_image="$original_image" | |
rm -rf $tag_file | |
wget -q https://hub.docker.com/v1/repositories/$original_image/tags -O - | jq -r '.[] | .name' >> $tag_file | |
while read -r line2; do | |
tag="$line2" | |
docker pull $original_image:$tag | |
docker tag $original_image:$tag $target_repo/$new_image:$tag | |
docker push $target_repo/$new_image:$tag | |
done < "$tag_file" | |
while read -r line3; do | |
tag="$line3" | |
# delete pushed images | |
docker image rm $original_image:$tag | |
docker image rm $target_repo/$new_image:$tag | |
done < "$tag_file" | |
done < "$img_file" | |
rm -rf $img_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want to do an scheduled sync of A SINGLE image in DockerHub (skipping what has been already migrated to GitHub Container Registry), check this script instead: https://gist.github.com/ferferga/7dc7bef353c2f41520a1a42d12f5e41c