你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
从 IoT Edge 设备上的连接注册表中拉取映像(即将弃用)
若要从连接注册表中拉取映像,请配置客户端令牌 ,并传递令牌凭据以访问注册表内容。
先决条件
在 Azure Cloud Shell 中使用 Bash 环境。 有关详细信息,请参阅 Azure Cloud Shell 中的 Bash 快速入门。
如需在本地运行 CLI 参考命令,请安装 Azure CLI。 如果在 Windows 或 macOS 上运行,请考虑在 Docker 容器中运行 Azure CLI。 有关详细信息,请参阅如何在 Docker 容器中运行 Azure CLI。
如果使用的是本地安装,请使用 az login 命令登录到 Azure CLI。 若要完成身份验证过程,请遵循终端中显示的步骤。 有关其他登录选项,请参阅使用 Azure CLI 登录。
出现提示时,请在首次使用时安装 Azure CLI 扩展。 有关扩展详细信息,请参阅使用 Azure CLI 的扩展。
运行 az version 以查找安装的版本和依赖库。 若要升级到最新版本,请运行 az upgrade。
- Azure 中的连接注册表资源。 有关部署步骤,请参阅快速入门:使用 Azure CLI 创建连接注册表。
- 已在 IoT Edge 设备上部署的连接注册表实例。 有关部署步骤,请参阅快速入门:将连接注册表部署到 IoT Edge 设备 或 教程:将连接注册表部署到嵌套 IoT Edge 设备。 在本文的命令中,连接注册表名称存储在环境变量 $CONNECTED_REGISTRY_RW 中。
创建范围映射
使用 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