Tutorial: Deploy and use Azure Container Registry (ACR)

Azure Container Registry (ACR) is a private registry for container images. A private container registry allows you to securely build and deploy your applications and custom code. In this tutorial, part two of seven, you deploy an ACR instance and push a container image to it. You learn how to:

  • Create an ACR instance
  • Tag a container image for ACR
  • Upload the image to ACR
  • View images in your registry

In later tutorials, you integrate your ACR instance with a Kubernetes cluster in AKS, and deploy an application from the image.

Before you begin

In the previous tutorial, you created a container image for a simple Azure Voting application. If you haven't created the Azure Voting app image, return to Tutorial 1: Prepare an application for AKS.

This tutorial requires that you're running the Azure CLI version 2.0.53 or later. Run az --version to find the version. If you need to install or upgrade, see Install Azure CLI.

Create an Azure Container Registry

Before creating an ACR, you need a resource group. An Azure resource group is a logical container into which you deploy and manage Azure resources.

  1. Create a resource group with the az group create command.
az group create --name myResourceGroup --location eastus
  1. Create an ACR instance with the az acr create command and provide your own unique registry name. The registry name must be unique within Azure, and contain 5-50 alphanumeric characters. In the rest of this tutorial, <acrName> is used as a placeholder for the container registry name. The Basic SKU is a cost-optimized entry point for development purposes that provides a balance of storage and throughput.
az acr create --resource-group myResourceGroup --name <acrName> --sku Basic

Log in to the container registry

Log in to your ACR using the az acr login command and provide the unique name given to the container registry in the previous step.

az acr login --name <acrName>

The command returns a Login Succeeded message once completed.

Tag a container image

To see a list of your current local images, use the docker images command.

docker images

The following example output shows a list of the current local Docker images:

REPOSITORY                                     TAG                 IMAGE ID            CREATED             SIZE
mcr.microsoft.com/azuredocs/azure-vote-front   v1                  84b41c268ad9        7 minutes ago       944MB
mcr.microsoft.com/oss/bitnami/redis            6.0.8               3a54a920bb6c        2 days ago          103MB

To use the azure-vote-front container image with ACR, you need to tag the image with the login server address of your registry. The tag is used for routing when pushing container images to an image registry.

To get the login server address, use the az acr list command and query for the loginServer.

az acr list --resource-group myResourceGroup --query "[].{acrLoginServer:loginServer}" --output table

Then, tag your local azure-vote-front image with the acrLoginServer address of the container registry. To indicate the image version, add :v1 to the end of the image name:

docker tag mcr.microsoft.com/azuredocs/azure-vote-front:v1 <acrLoginServer>/azure-vote-front:v1

To verify the tags are applied, run docker images again.

docker images

The following example output shows an image tagged with the ACR instance address and a version number:

REPOSITORY                                      TAG                 IMAGE ID            CREATED             SIZE
mcr.microsoft.com/azuredocs/azure-vote-front    v1                  84b41c268ad9        16 minutes ago      944MB
mycontainerregistry.azurecr.io/azure-vote-front v1                  84b41c268ad9        16 minutes ago      944MB
mcr.microsoft.com/oss/bitnami/redis             6.0.8               3a54a920bb6c        2 days ago          103MB

Push images to registry

Push the azure-vote-front image to your ACR instance using the docker push command. Make sure to provide your own acrLoginServer address for the image name.

docker push <acrLoginServer>/azure-vote-front:v1

It may take a few minutes to complete the image push to ACR.

List images in registry

To return a list of images that have been pushed to your ACR instance, use the az acr repository list command, providing your own <acrName>.

az acr repository list --name <acrName> --output table

The following example output lists the azure-vote-front image as available in the registry:

Result
----------------
azure-vote-front

To see the tags for a specific image, use the az acr repository show-tags command.

az acr repository show-tags --name <acrName> --repository azure-vote-front --output table

The following example output shows the v1 image tagged in a previous step:

Result
--------
v1

Next steps

In this tutorial, you created an ACR and pushed an image to use in an AKS cluster. You learned how to:

  • Create an ACR instance
  • Tag a container image for ACR
  • Upload the image to ACR
  • View images in your registry

In the next tutorial, you'll learn how to deploy a Kubernetes cluster in Azure.