Skip to content

Instantly share code, notes, and snippets.

@ckocyigit
Created April 1, 2024 17:42
Show Gist options
  • Select an option

  • Save ckocyigit/d6f3851294312171464cb9bd4094f0c4 to your computer and use it in GitHub Desktop.

Select an option

Save ckocyigit/d6f3851294312171464cb9bd4094f0c4 to your computer and use it in GitHub Desktop.
Completely migrate one container registry to another
#!/bin/bash
# Define source and destination registry
source_registry="https://source.registry.com"
destination_registry="https://destination.registry.com"
# Authenticate if needed
auth="--user <username>:<password>" # if authentication is required, otherwise leave it empty
auth_param=""
if [ -n "$auth" ]; then
auth_param="-u $auth"
fi
# Get list of repositories in source registry
echo "Fetching list of repositories from source registry..."
repositories=$(curl -s $auth_param -X GET $source_registry/v2/_catalog | jq -r '.repositories[]')
# Iterate through each repository, get list of tags, pull from source registry, and push to destination registry
for repository in $repositories; do
echo "Fetching list of tags for repository: $repository"
tags=$(curl -s $auth_param -X GET $source_registry/v2/$repository/tags/list | jq -r '.tags[]')
# Iterate through each tag, pull from source registry and push to destination registry
for tag in $tags; do
echo "Pulling $repository:$tag from source registry..."
docker pull $source_registry/$repository:$tag
echo "Tagging and pushing $repository:$tag to destination registry..."
docker tag $source_registry/$repository:$tag $destination_registry/$repository:$tag
docker push $destination_registry/$repository:$tag
docker rmi $destination_registry/$repository:$tag
done
done
echo "All images copied to destination registry."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment