Friday, September 6, 2019

Managing a simple Azure Container Registry

Azure Container Registry provides an excellent support for maintaining and distributing containers across multiple regions. But for this article, lets focus on a simpler container registry where my requirement is likely to host a few services on a Kubernetes Cluster. 

Publishing to Container Registry


You can simply use PowerShell. A sample code for uploading a local docker image to ACR can be done with the following command. 

First you need to login to Azure using az login command. Then,

az acr login -n <ContainerRegistryName>
docker tag <LocalImageName>:<LocalTag> <ACRName>.azurecr.io/<Repository>:<Tag>
docker push <ACRName>.azurecr.io/<Repository>:<Tag>


These commands will upload the image to Azure Container Registry. 

But if you are using a latest Visual Studio version and is building a .NET Core App you can just right click on project and select Publish to an Azure Container Registry. A screenshot of that can be seen below.



Maintaining Different Tags

The default tag name of a published image is 'latest'. But you can create new images and add tags. Imagine you are in need of quickly testing a changes included version of your new image. You can create or use the existing deployment yaml file and deploy it to Kubernetes in seconds. You can easily revert back to the older tag with the same deployment yaml file. 

When maintaining multiple images, you can feel safer to remove some of them with a new release or the older images getting obsolete. You can use the Azure portal to delete as well. If you think to keep the image, you can untag it as well. 

My two cents is if it is an image relevant to the current build version of the solution and you are having a high amount of images already tagged, just untag them. The once untagged can be deleted from the container registry with the following command.

PowerShell variables $registry means the registry name and $repository means the name of the repository within that registry.

az acr repository show-manifests --name $registry --repository $repository --query "[?tags[0]==null].digest" -o tsv `
    | %{ az acr repository delete --name $registry --image $repository@$_ --yes }

If you prefer just to view them and not to delete them, you can see all untagged images within the repository with the below command. 

az acr repository show-manifests --name $registry --repository $repository --query "[?tags[0]==null]" -o tsv

No comments:

Post a Comment