Create a container registry using the Azure CLI

Azure Container Registry is a managed Docker container registry service used for storing private Docker container images. This guide details creating an Azure Container Registry instance using the Azure CLI.

This quickstart requires that you are running the Azure CLI version 2.0.12 or later. Run az --version to find the version. If you need to install or upgrade, see Install Azure CLI 2.0.

You must also have Docker installed locally. Docker provides packages that easily configure Docker on any Mac, Windows, or Linux system.

Create a resource group

Create a resource group with the az group create command. An Azure resource group is a logical container into which Azure resources are deployed and managed.

The following example creates a resource group named myResourceGroup in the eastus location.

az group create --name myResourceGroup --location eastus

Create a container registry

In this quickstart, we create a Basic registry. Azure Container Registry is available in several different SKUs, described briefly in the following table. For extended details on each, see Container registry SKUs.

Azure Container Registry is available in several SKUs: Basic, Managed_Basic, Managed_Standard, and Managed_Premium. Although the Managed_* SKUs provide advanced capabilities like managed storage and Webhooks, they're currently unavailable in some Azure regions when using the Azure CLI. We select the Basic SKU in this quickstart due to its availability in all regions.

Note

Managed registries are currently available in all regions. However, the current version of the Azure CLI does not yet support creating a managed registry in all regions. Support will be available in the next version of the Azure CLI. Prior to its release, please use the Azure portal to create managed registries.

Create an ACR instance using the az acr create command.

The name of the registry must be unique. In the following example myContainerRegistry007 is used. Update this to a unique value.

az acr create --name myContainerRegistry007 --resource-group myResourceGroup --sku Basic

When the registry is created, the output is similar to the following:

{
  "adminUserEnabled": false,
  "creationDate": "2017-09-08T22:32:13.175925+00:00",
  "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.ContainerRegistry/registries/myContainerRegistry007",
  "location": "eastus",
  "loginServer": "myContainerRegistry007.azurecr.io",
  "name": "myContainerRegistry007",
  "provisioningState": "Succeeded",
  "resourceGroup": "myResourceGroup",
  "sku": {
    "name": "Basic",
    "tier": "Basic"
  },
  "storageAccount": {
    "name": "mycontainerregistr223140"
  },
  "tags": {},
  "type": "Microsoft.ContainerRegistry/registries"
}

Throughout the rest of this quickstart, we use <acrname> as a placeholder for the container registry name.

Log in to ACR

Before pushing and pulling container images, you must log in to the ACR instance. To do so, use the az acr login command.

az acr login --name <acrname>

The command returns a 'Login Succeeded' message once completed.

Push image to ACR

To push an image to an Azure Container registry, you must first have an image. If needed, run the following command to pull a pre-created image from Docker Hub.

docker pull microsoft/aci-helloworld

The image needs to be tagged with the ACR login server name. Run the following command to return the login server name of the ACR instance.

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

Tag the image using the docker tag command. Replace with the login server name of your ACR instance.

docker tag microsoft/aci-helloworld <acrLoginServer>/aci-helloworld:v1

Finally, use docker push to push the image to the ACR instance. Replace with the login server name of your ACR instance.

docker push <acrLoginServer>/aci-helloworld:v1

List container images

The following example lists the repositories in a registry:

az acr repository list -n <acrname> -o table

Output:

Result
----------------
aci-helloworld

The following example lists the tags on the aci-helloworld repository.

az acr repository show-tags -n <acrname> --repository aci-helloworld -o table

Output:

Result
--------
v1

Clean up resources

When no longer needed, you can use the az group delete command to remove the resource group, ACR instance, and all container images.

az group delete --name myResourceGroup

Next steps

In this quickstart, you created an Azure Container Registry with the Azure CLI. If you would like to use Azure Container Registry with Azure Container Instances, continue to the Azure Container Instances tutorial.