快速入门:使用 ARM 模板创建异地复制容器注册表Quickstart: Create a geo-replicated container registry by using an ARM template

本快速入门介绍如何使用 Azure 资源管理器模板(ARM 模板)创建 Azure 容器注册表实例。This quickstart shows how to create an Azure Container Registry instance by using an Azure Resource Manager template (ARM 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.

如果你的环境满足先决条件,并且你熟悉如何使用 ARM 模板,请选择“部署到 Azure”按钮。If your environment meets the prerequisites and you're familiar with using ARM templates, select the Deploy to Azure button. Azure 门户中会打开模板。The template will open in the Azure portal.

备注

当我们从 https://raw.githubusercontent.com/ 网站下载特定模板并尝试从自定义模板进行部署时,有时会遇到某些问题。When we download the specific template from https://raw.githubusercontent.com/ website and try to deploy from custom template, there will be encounter certain issue sometime.

githubusercontent 前缀模板部署问题

我们可以按照以下指示在 Azure 中国云环境中部署模板:We can follow the directions below to deploy template on Azure China Cloud environment:

  1. 复制模板 URI,通过更改前缀、中缀和模板文件名来转换 URI。Copy the template URI, convert the URI by changing the prefix, infix, and tempalte file name. 例如,源 URI 是 https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-cosmosdb-sql-autoscale/azuredeploy.jsonFor exsample: the origin URI is https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-cosmosdb-sql-autoscale/azuredeploy.json

    类别Category 原始值Original value 转换后的值Converted value 操作Action
    前缀Prefix https://raw.githubusercontent.com https://github.com 更新Update
    中辍Infix blob master 之前添加(Git 存储库的默认分支名称)Add before master(default branch name of git repository)
    模板文件名Template file name azuredeploy.jsonazuredeploy.json 你的下载模板文件名your download tempalte file name updateupdate

    修改后,转换后的 URI 看起来将类似于 https://github.com/Azure/azure-quickstart-templates/blob/master/101-cosmosdb-sql-autoscale/azuredeploy.jsonAfter modified, the converted URI will show like https://github.com/Azure/azure-quickstart-templates/blob/master/101-cosmosdb-sql-autoscale/azuredeploy.json.

  2. 复制转换后的 URI,并在 Internet 浏览器中手动下载特定的模板内容。Copy the converted URI and download the specific template content in Internet browsers manully.

  3. 在门户的“自定义部署”页中,选择“在编辑器中生成自己的模板”。Select Build your own template in the editor in the Custom deployment page of portal.

  4. 将下载的模板内容复制到“编辑模板”页中,并按照 Azure 中国云的要求更新参数,例如 Azure 中国云环境不支持的终结点、位置、VM 映像、VM 大小、SKU 和资源提供程序的 API 版本。Copy the downloaded template content in the Edit template page and update the parameters to meet Azure China Cloud, such as endpoint, Location, VM images, VM sizes, SKU , and resource-provider's API Version that is not supported on Azure China Cloud environment.

  5. 选择“保存”以返回“自定义部署”页。Select save to return the Custom deployment page.

  6. 选择“我同意上述条款和条件”。Select I agree to the terms and condition stated above.

  7. 选择“购买”。Select Purchase.

部署到 Azure Deploy to Azure

先决条件Prerequisites

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

查看模板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",
      "defaultValue": "Premium",
      "allowedValues": [
        "Premium"
      ],
      "metadata": {
        "description": "Tier of your Azure Container Registry. Geo-replication requires Premium SKU."
      }
    },
    "acrReplicaLocation": {
      "type": "string",
      "metadata": {
        "description": "Short name for registry replica location."
      }
    }
  },
  "resources": [
    {
      "comments": "Container registry for storing docker images",
      "type": "Microsoft.ContainerRegistry/registries",
      "apiVersion": "2019-12-01-preview",
      "name": "[parameters('acrName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('acrSku')]",
        "tier": "[parameters('acrSku')]"
      },
      "tags": {
        "displayName": "Container Registry",
        "container.registry": "[parameters('acrName')]"
      },
      "properties": {
        "adminUserEnabled": "[parameters('acrAdminUserEnabled')]"
      }
    },
    {
      "type": "Microsoft.ContainerRegistry/registries/replications",
      "apiVersion": "2019-12-01-preview",
      "name": "[concat(parameters('acrName'), '/', parameters('acrReplicaLocation'))]",
      "location": "[parameters('acrReplicaLocation')]",
      "dependsOn": [
        "[resourceId('Microsoft.ContainerRegistry/registries/', parameters('acrName'))]"
      ],
      "properties": {}
    }
  ],
  "outputs": {
    "acrLoginServer": {
      "value": "[reference(resourceId('Microsoft.ContainerRegistry/registries',parameters('acrName')),'2019-12-01-preview').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.

    部署到 Azure Deploy 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.

    • 已启用 Acr 管理员用户:接受默认值。Acr Admin User Enabled: accept the default value.

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

    • Acr Sku:接受默认值。Acr Sku: accept the default value.

    • 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.

删除资源组 Delete resource group

后续步骤Next steps

在本快速入门中,你已使用 ARM 模板创建了 Azure 容器注册表,并在其他位置配置了注册表副本。In this quickstart, you created an Azure Container Registry with an ARM 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:

创建和部署你的第一个 ARM 模板[Tutorial: Create and deploy your first ARM template