When someone asks to migrate an ACR from one Azure subscription to another azure subscription, it feels like a tedious task. Because you must migrate Image repositories and all the image tags that are in those repositories.
Traditionally, you can use
az acr import command to achieve this. But when the number of repositories increases, it takes an exponentially high unproductive time.
I have recently gone through this situation and thought to automate this process. Below
z shell script, I have come up, which may help you in those scenarios.
Prerequisites to use this command:
- Docker Desktop/ Docker binary is installed
- AZ CLI is installed
- first create a new Azure Container Registry
- login to the new repository using AZ CLI (
az acrlogin command)
- Keep the below information ready
- Name of your old repository
- Username of the old repository
- Password of the old repository
- Now Run the below shell script
echo "Enter the Source ACR Name: " read SourceAcrName echo "Enter the Source ACR User Name: " read SourceAcrUsrName echo "Enter the Source ACR Password: " read -s SourceAcrpasswd echo "Enter the Destination ACR Name: " read DestinationAcrName Repos=$(az acr repository list --name $SourceAcrName --username=$SourceAcrUsrName --password=$SourceAcrpasswd | tr -d ' "" ,'| grep "\S") echo $Repos | while read RepoName do Tags=$(az acr repository show-tags -n $SourceAcrName --repository $line --username=$SourceAcrUsrName --password=$SourceAcrpasswd | tr -d ' "" ,'| grep "\S") echo $Tags | while read TagName do az acr import \ --name $DestinationAcrName \ --source $SourceAcrName.azurecr.io/$RepoName:$TagName \ --image $RepoName:$TagName \ --username=$SourceAcrName \ --password=$SourceAcrpasswd \ --no-wait done done
Note: in this Shell Script Source ACR Name is old repository name. Source ACR Username is Username of the old repository. Source ACR Password is Password of the old repository. This is written for
zshshell, if you would like to use it for
bashshell please change
Hope this helps. Let me know what you think in the comments below.