你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

快速入门:使用 Azure CLI 创建连接的注册表

在本快速入门中,你将使用 Azure CLI 在 Azure 中创建连接的注册表资源。 Azure 容器注册表的连接的注册表功能允许远程或在本地部署注册表,以及将映像和其他项目与云注册表同步。

在这里,为云注册表创建两个连接注册表资源:一个连接注册表允许读写(项目拉取和推送)功能,另一个允许只读功能。

创建连接注册表后,可以按照其他指南在本地或远程基础结构上部署和使用该注册表。

先决条件

  • Azure 容器注册表 - 如果还没有容器注册表,请在支持连接的注册表的区域创建一个(需要高级层)。

为云注册表启用专用数据终结点

使用 az acr update 命令为云中的 Azure 容器注册表启用专用数据终结点。 连接的注册表与云注册表进行通信需要此步骤。

# Set the REGISTRY_NAME environment variable to identify the existing cloud registry
REGISTRY_NAME=<container-registry-name>

az acr update --name $REGISTRY_NAME \
  --data-endpoint-enabled

将映像导入到云注册表

使用 az acr import 命令将以下容器映像导入到云注册表。 如果已导入这些映像,请跳过此步骤。

连接注册表映像

为了支持嵌套的 IoT Edge 方案,连接注册表运行时的容器映像必须在专用 Azure 容器注册表中可用。 使用 az acr import 命令将连接注册表映像导入专用注册表。

# Use the REGISTRY_NAME variable in the following Azure CLI commands to identify the registry
REGISTRY_NAME=<container-registry-name>

az acr import \
  --name $REGISTRY_NAME \
  --source mcr.microsoft.com/acr/connected-registry:0.8.0

IoT Edge 和 API 代理映像

若要支持嵌套 IoT Edge 上连接的注册表,需要为 IoT Edge 和 API 代理部署模块。 将这些映像导入专用注册表。

IoT Edge API 代理模块允许 IoT Edge 设备在同一端口(例如 443)上使用 HTTPS 协议公开多个服务。

az acr import \
  --name $REGISTRY_NAME \
  --source mcr.microsoft.com/azureiotedge-agent:1.2.4

az acr import \
  --name $REGISTRY_NAME \
  --source mcr.microsoft.com/azureiotedge-hub:1.2.4

az acr import \
  --name $REGISTRY_NAME \
  --source mcr.microsoft.com/azureiotedge-api-proxy:1.1.2

az acr import \
  --name $REGISTRY_NAME \
  --source mcr.microsoft.com/azureiotedge-diagnostics:1.2.4

Hello-world 映像

若要测试连接注册表,请导入 hello-world 映像。 此存储库将与连接注册表同步,并由连接注册表客户端拉取。

az acr import \
  --name $REGISTRY_NAME \
  --source mcr.microsoft.com/hello-world:1.1.2

为读写功能创建连接的注册表资源

使用 az acr connected-registry create 命令创建连接的注册表。 连接的注册表名称必须以字母开头且仅包含字母数字字符。 注册表名称长度必须为 5 到 40 个字符,并且在此 Azure 容器注册表的层次结构中是唯一的。

# Set the CONNECTED_REGISTRY_RW environment variable to provide a name for the connected registry with read/write functionality
CONNECTED_REGISTRY_RW=<connnected-registry-name>

az acr connected-registry create --registry $REGISTRY_NAME \
  --name $CONNECTED_REGISTRY_RW \
  --repository "hello-world" "acr/connected-registry" "azureiotedge-agent" "azureiotedge-hub" "azureiotedge-api-proxy"

此命令创建一个连接的注册表资源,其名称为 $CONNECTED_REGISTRY_RW 的值,并将其链接到名为 $REGISTRY_NAME 的值的云注册表 。 在稍后的快速入门指南中,你将了解用于部署连接的注册表的选项。

  • 部署后,指定的存储库将在云注册表和连接的注册表之间同步。

  • 由于没有为连接的注册表指定 --mode 选项,所以它是在默认的 ReadWrite 模式下创建的。

  • 由于没有为此连接的注册表定义同步计划,因此存储库将在不中断的情况下在云注册表和连接的注册表之间同步。

    重要

    若要支持下层无法访问 Internet 的嵌套方案,必须始终允许同步 acr/connected-registry 存储库。 此存储库包含连接注册表运行时的映像。

为只读功能创建连接的注册表资源

也可使用 az acr connected-registry create 命令创建具有只读功能的连接的注册表。

# Set the CONNECTED_REGISTRY_READ environment variable to provide a name for the connected registry with read-only functionality
CONNECTED_REGISTRY_RO=<connnected-registry-name>
az acr connected-registry create --registry $REGISTRY_NAME \
  --parent $CONNECTED_REGISTRY_RW \
  --name $CONNECTED_REGISTRY_RO \
  --repository "hello-world" "acr/connected-registry" "azureiotedge-agent" "azureiotedge-hub" "azureiotedge-api-proxy" \
  --mode ReadOnly

此命令创建一个连接的注册表资源,其名称为 $CONNECTED_REGISTRY_RO 的值,并将其链接到名为 $REGISTRY_NAME 的值的云注册表 。

  • 指定的存储库将在名为 $CONNECTED_REGISTRY_RW 的值的父注册表与部署后的连接的注册表之间同步。
  • 此资源在 ReadOnly 模式下创建,该模式将在部署后启用只读(项目拉取)功能。
  • 由于没有为此连接的注册表定义同步计划,因此存储库将在不中断的情况下在父注册表和连接的注册表之间同步。

验证是否已创建资源

可以使用连接的注册表 az acr connected-registry list 命令来验证是否已创建资源。

az acr connected-registry list \
  --registry $REGISTRY_NAME \
  --output table

应会看到如下响应。 由于连接的注册表尚未部署,连接状态为“脱机”表示它们当前与云端断开连接。

NAME                 MODE        CONNECTION STATE    PARENT               LOGIN SERVER    LAST SYNC (UTC)
-------------------  --------    ------------------  -------------------  --------------  -----------------
myconnectedregrw    ReadWrite    Offline
myconnectedregro    ReadOnly     Offline             myconnectedregrw

后续步骤

在本快速入门中,你使用 Azure CLI 在 Azure 中创建了两个连接的注册表资源。 这些新的连接的注册表资源与云注册表相关联,并且允许项目与云注册表同步。

继续阅读连接注册表部署指南,了解如何在 IoT Edge 基础结构上部署和使用连接注册表。