快速入门:使用资源管理器模板创建异地复制容器注册表Quickstart: Create a geo-replicated container registry by using a Resource Manager template

本快速入门介绍如何使用 Azure 资源管理器模板创建 Azure 容器注册表实例。This quickstart shows how to create an Azure Container Registry instance by using an Azure Resource Manager template. 该模板会设置一个异地复制注册表,使其自动在多个 Azure 区域之间同步注册表内容。The template sets up a geo-replicated registry, which automatically synchronizes registry content across more than one Azure region. 借助异地复制,可以从区域部署对映像进行近网络访问,同时提供单一管理体验。Geo-replication enables network-close access to images from regional deployments, while providing a single management experience. 这是高级注册表服务层级的一项功能。It's a feature of the Premium registry service tier.

ARM 模板是定义项目基础结构和配置的 JavaScript 对象表示法 (JSON) 文件。An ARM template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. 该模板使用声明性语法,使你可以声明要部署的内容,而不需要编写一系列编程命令来进行创建。The template uses declarative syntax, which lets you state what you intend to deploy without having to write the sequence of programming commands to create it.

如果没有 Azure 订阅,请在开始之前创建一个免费帐户。If you don't have an Azure subscription, create a free account before you begin.

先决条件Prerequisites

无。None.

创建异地复制注册表Create a geo-replicated registry

查看模板Review the template

本快速入门中使用的模板来自 Azure 快速启动模板The template used in this quickstart is from Azure Quickstart Templates. 该模板会设置注册表和其他区域副本。The template sets up a registry and an additional regional replica.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "acrName": {
      "type": "string",
      "defaultValue": "[concat('acr', uniqueString(resourceGroup().id))]",
      "minLength": 5,
      "maxLength": 50,
      "metadata": {
        "description": "Globally unique name of your Azure Container Registry"
      }
    },
    "acrAdminUserEnabled": {
      "type": "bool",
      "defaultValue": false,
      "metadata": {
        "description": "Enable admin user that has push / pull permission to the registry."
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for registry home replica."
      }
    },
    "acrSku": {
      "type": "string",
      "metadata": {
        "description": "Tier of your Azure Container Registry. Geo-replication requires Premium SKU."
      },
      "defaultValue": "Premium",
      "allowedValues": [
        "Premium"
      ]
    },
    "acrReplicaLocation": {
      "type": "string",
      "metadata": {
        "description": "Short name for registry replica location."
      }
    }
  },
  "resources": [
    {
      "name": "[parameters('acrName')]",
      "type": "Microsoft.ContainerRegistry/registries",
      "apiVersion": "2019-05-01",
      "location": "[parameters('location')]",
      "comments": "Container registry for storing docker images",
      "tags": {
        "displayName": "Container Registry",
        "container.registry": "[parameters('acrName')]"
      },
      "sku": {
        "name": "[parameters('acrSku')]",
        "tier": "[parameters('acrSku')]"
      },
      "properties": {
        "adminUserEnabled": "[parameters('acrAdminUserEnabled')]"
      }
    },
    {
      "name": "[concat(parameters('acrName'), '/', parameters('acrReplicaLocation'))]",
      "type": "Microsoft.ContainerRegistry/registries/replications",
      "apiVersion": "2019-05-01",
      "location": "[parameters('acrReplicaLocation')]",
      "properties": {},
      "dependsOn": [
        "[concat('Microsoft.ContainerRegistry/registries/', parameters('acrName'))]"
      ]
    }
  ],
  "outputs": {
    "acrLoginServer": {
      "value": "[reference(resourceId('Microsoft.ContainerRegistry/registries',parameters('acrName')),'2019-05-01').loginServer]",
      "type": "string"
    }
  }
}

该模板中定义了以下资源:The following resources are defined in the template:

  • Microsoft.ContainerRegistry/registries:创建 Azure 容器注册表Microsoft.ContainerRegistry/registries: create an Azure container registry

  • Microsoft.ContainerRegistry/registries/replications:创建容器注册表副本Microsoft.ContainerRegistry/registries/replications: create a container registry replica

可以在快速入门模板库中找到更多 Azure 容器注册表模板示例。More Azure Container Registry template samples can be found in the quickstart template gallery.

部署模板Deploy the template

  1. 选择下图登录到 Azure 并打开一个模板。Select the following image to sign in to Azure and open a template.

    部署到 AzureDeploy to Azure

  2. 选择或输入以下值。Select or enter the following values.

    • 订阅:选择一个 Azure 订阅。Subscription: select an Azure subscription.

    • 资源组:选择“新建”,为资源组输入一个独一无二的名称,然后选择“确定”。Resource group: select Create new, enter a unique name for the resource group, and then select OK.

    • 位置:选择资源组的位置。Location: select a location for the resource group. 示例:中国北部Example: China North.

    • Acr 名称:接受为注册表生成的名称,或者输入一个名称。Acr Name: accept the generated name for the registry, or enter a name. 它必须全局唯一。It must be globally unique.

    • 位置:接受为注册表的主副本生成的位置,或输入一个位置,例如“中国北部”。Location: accept the generated location for the registry's home replica, or enter a location such as China North.

    • Acr 副本位置:使用区域的短名称输入注册表副本的位置。Acr Replica Location: enter a location for the registry replica, using the region's short name. 该位置必须与主注册表的位置不同。It must be different from the home registry location. 示例:chinanorth。Example: chinanorth.

    • 我同意上述条款和条件:选中。I agree to the terms and conditions stated above: Select.

      模板属性

  3. 如果接受条款和条件,请选择“购买”。If you accept the terms and conditions, select Purchase. 成功创建注册表后,你会收到通知:After the registry has been created successfully, you get a notification:

    门户通知

使用 Azure 门户部署模板。The Azure portal is used to deploy the template. 除了 Azure 门户之外,还可以使用 Azure PowerShell、Azure CLI 和 REST API。In addition to the Azure portal, you can use the Azure PowerShell, Azure CLI, and REST API. 若要了解其他部署方法,请参阅部署模板To learn other deployment methods, see Deploy templates.

查看已部署的资源Review deployed resources

使用 Azure 门户或诸如 Azure CLI 之类的工具来查看容器注册表的属性。Use the Azure portal or a tool such as the Azure CLI to review the properties of the container registry.

  1. 在门户中,搜索“容器注册表”,然后选择所创建的容器注册表。In the portal, search for Container Registries, and select the container registry you created.

  2. 在“概述”页上,记下注册表的“登录服务器” 。On the Overview page, note the Login server of the registry. 使用 Docker 标记映像并将其推送到注册表时,请使用此 URI。Use this URI when you use Docker to tag and push images to your registry. 有关信息,请参阅使用 Docker CLI 推送第一个映像For information, see Push your first image using the Docker CLI.

    注册表概述

  3. 在“复制”页上,确认主副本和通过该模板添加的副本的位置。On the Replications page, confirm the locations of the home replica and the replica added through the template. 如果需要,可在此页上添加更多副本。If desired, add more replicas on this page.

    注册表复制

清理资源Clean up resources

如果不再需要资源组、注册表和注册表副本,请将其删除。When you no longer need them, delete the resource group, the registry, and the registry replica. 为此,请访问 Azure 门户,选择包含注册表的资源组,然后选择“删除资源组”。To do so, go to the Azure portal, select the resource group that contains the registry, and then select Delete resource group.

后续步骤Next steps

在本快速入门中,你使用资源管理器模板创建了 Azure 容器注册表,并在其他位置配置了注册表副本。In this quickstart, you created an Azure Container Registry with a Resource Manager template, and configured a registry replica in another location. 请继续阅读 Azure 容器注册表教程,以更深入地了解 ACR。Continue to the Azure Container Registry tutorials for a deeper look at ACR.

有关引导你完成模板创建过程的分步教程,请参阅:For a step-by-step tutorial that guides you through the process of creating a template, see: