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

从 IoT Edge 设备上的连接注册表中拉取映像

若要从连接注册表中拉取映像,请配置客户端令牌 ,并传递令牌凭据以访问注册表内容。

先决条件

创建范围映射

使用 az acr scope-map create 命令创建读取hello-world存储库访问的范围映射:

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

az acr scope-map create \
  --name hello-world-scopemap \
  --registry $REGISTRY_NAME \
  --repository hello-world content/read \
  --description "Scope map for the connected registry."

创建客户端令牌

使用 az acr token create 命令创建客户端令牌,并将其与新建的范围映射相关联:

az acr token create \
  --name myconnectedregistry-client-token \
  --registry $REGISTRY_NAME \
  --scope-map hello-world-scopemap

该命令将返回有关新生成的令牌(包括密码)的详细信息。

重要

请确保保存生成的密码。 这些是一次性密码,无法检索。 你可以使用 az acr token credential generate 命令生成新密码。

用客户端令牌更新连接注册表

使用 az acr connected-registry update 命令,用新建的客户端令牌更新连接注册表。

az acr connected-registry update \
  --name $CONNECTED_REGISTRY_RW \
  --registry $REGISTRY_NAME \
  --add-client-token myconnectedregistry-client-token

从连接注册表中拉取映像

在有权访问 IoT Edge 设备的计算机上,使用以下示例命令,使用客户端令牌凭据登录到连接注册表。 有关管理登录凭据的最佳做法,请参阅 docker login 命令参考。

注意

如果将连接注册表设置为不安全注册表,请更新 Docker 守护程序配置中的不安全注册表列表,以便在 IoT Edge 设备上包含所连接注册表的 IP 地址(或 FQDN)和端口。 此配置应仅用于测试目的。 有关详细信息,请参阅测试不安全注册表

docker login --username myconnectedregistry-client-token \
  --password <token_password> <IP_address_or_FQDN_of_connected_registry>:<port>

对于 IoT Edge 方案,请确保包含用于访问设备上的连接注册表的端口。 示例:

docker login --username myconnectedregistry-client-token \
  --password xxxxxxxxxxx 192.0.2.13:8000

然后,使用以下命令拉取hello-world 映像:

docker pull <IP_address_or_FQDN_of_connected_registry>:<port>/hello-world

后续步骤