Deploy and use Azure Container Registry
This is part two of a three-part tutorial. In the previous step, a container image was created for a simple web application written in Node.js. In this tutorial, you push the image to an Azure Container Registry. If you have not created the container image, return to Tutorial 1 – Create container image.
The Azure Container Registry is an Azure-based, private registry, for Docker container images. This tutorial walks through deploying an Azure Container Registry instance, and pushing a container image to it. Steps completed include:
- Deploying an Azure Container Registry instance
- Tagging container image for Azure Container Registry
- Uploading image to Azure Container Registry
In subsequent tutorials, you deploy the container from your private registry to Azure Container Instances.
Before you begin
This tutorial requires that you are running the Azure CLI version 2.0.21 or later. Run
az --version to find the version. If you need to install or upgrade, see Install Azure CLI 2.0.
Azure Cloud Shell does not include the Docker components required to complete every step this tutorial. Therefore, we recommend a local installation of the Azure CLI and Docker development environment.
Deploy Azure Container Registry
When deploying an Azure Container Registry, you first need a resource group. An Azure resource group is a logical collection into which Azure resources are deployed and managed.
Create a resource group with the az group create command. In this example, a resource group named myResourceGroup is created in the eastus region.
az group create --name myResourceGroup --location eastus
Create an Azure container registry with the az acr create command. The container registry name must be unique within Azure, and must contain 5-50 alphanumeric characters. Replace
<acrName> with a unique name for your registry:
az acr create --resource-group myResourceGroup --name <acrName> --sku Basic
For example, to create an Azure container registry named mycontainerregistry082:
az acr create --resource-group myResourceGroup --name mycontainerregistry082 --sku Basic --admin-enabled true
Throughout the rest of this tutorial, we use
<acrName> as a placeholder for the container registry name that you chose.
Container registry login
You must log in to your ACR instance before pushing images to it. Use the az acr login command to complete the operation. You must provide the unique name given to the container registry when it was created.
az acr login --name <acrName>
The command returns a
Login Succeeded message once completed.
Tag container image
To deploy a container image from a private registry, the image needs to be tagged with the
loginServer name of the registry.
To see a list of current images, use the
docker images command.
REPOSITORY TAG IMAGE ID CREATED SIZE aci-tutorial-app latest 5c745774dfa9 39 seconds ago 68.1 MB
To get the loginServer name, run the following command. Replace
<acrName> with the name of your container registry.
az acr show --name <acrName> --query loginServer --output table
Result ------------------------ mycontainerregistry082.azurecr.io
Tag the aci-tutorial-app image with the loginServer of your container registry. Also, add
:v1 to the end of the image name. This tag indicates the image version number. Replace
<acrLoginServer> with the result of the
az acr show command you just executed.
docker tag aci-tutorial-app <acrLoginServer>/aci-tutorial-app:v1
Once tagged, run
docker images to verify the operation.
REPOSITORY TAG IMAGE ID CREATED SIZE aci-tutorial-app latest 5c745774dfa9 39 seconds ago 68.1 MB mycontainerregistry082.azurecr.io/aci-tutorial-app v1 a9dace4e1a17 7 minutes ago 68.1 MB
Push image to Azure Container Registry
Push the aci-tutorial-app image to the registry with the
docker push command. Replace
<acrLoginServer> with the full login server name you obtain in the earlier step.
docker push <acrLoginServer>/aci-tutorial-app:v1
push operation should take a few seconds to a few minutes depending on your Internet connection, and output is similar to the following:
The push refers to a repository [mycontainerregistry082.azurecr.io/aci-tutorial-app] 3db9cac20d49: Pushed 13f653351004: Pushed 4cd158165f4d: Pushed d8fbd47558a8: Pushed 44ab46125c35: Pushed 5bef08742407: Pushed v1: digest: sha256:ed67fff971da47175856505585dcd92d1270c3b37543e8afd46014d328f05715 size: 1576
List images in Azure Container Registry
To return a list of images that have been pushed to your Azure Container registry, use the az acr repository list command. Update the command with the container registry name.
az acr repository list --name <acrName> --output table
Result ---------------- aci-tutorial-app
And then to see the tags for a specific image, use the az acr repository show-tags command.
az acr repository show-tags --name <acrName> --repository aci-tutorial-app --output table
Result -------- v1
In this tutorial, an Azure Container Registry was prepared for use with Azure Container Instances, and the container image was pushed. The following steps were completed:
- Deployed an Azure Container Registry instance
- Tagged a container image for Azure Container Registry
- Uploaded an image to Azure Container Registry
Advance to the next tutorial to learn about deploying the container to Azure using Azure Container Instances.