Azure 容器实例 Python API - 无法从 Azure 容器注册表获取图像
Azure Container Instances Python API - fails to fetch image from Azure Container Registry
基于 this guide I wrote this sample code,适用于默认图像(“microsoft/aci-helloworld”),但在我的 azure 订阅中更改为来自 Azure 容器注册表的图像时失败。
错误信息是:
The image 'mytest.azurecr.io/myimage:latest' in container group '' is not accessible. Please check the image and registry credential.
我找到了这个 但示例代码已经使用了该问题的解决方案(使用基于文件的身份验证)。
我也试过我的图像名称 with/without “:latest” 后缀,并确保“docker pull mytest.azurecr.io/myimage:latest " 成功。
编辑:添加 ACR 截图:
注意:我也尝试了 C# 代码示例(根据 ),但收到了同样的错误。我可能遗漏了一些与配置相关的东西。如何允许服务主体访问 ACR?我根据指南创建了主体:
az ad sp create-for-rbac --sdk-auth > my.azureauth
这是否意味着该服务主体应该有权访问同一订阅中的任何 ACR?
根据我的经验,你得到的错误是图片名错误导致的,说明在ACR中找不到该图片。如屏幕截图所示,图像名称必须是 xxxtestaci.azurecr.io/tempxxx:latest
或 xxxtestaci.azurecr.io/tempxxx
。重现错误也很容易:
而ACR的凭证,可以按照Azure Container Registry authentication with service principals中的步骤进行。但是,如果您在创建资源和从 ACR 中提取图像时仅使用一个服务主体,我建议您向服务主体授予 Contributor
角色。
这是否意味着该服务主体应该有权访问同一订阅中的任何 ACR?
默认情况下,CLI 命令az ad sp create-for-rbac
使用默认参数--role Contributor
。所以是的,它可以访问同一订阅中的任何 ACR。
缺少的部分是添加 ACR 的凭据。固定代码如下所示(您必须在 ImageRegistryCredential 实例中设置服务器、用户名和密码):
credentials = [ImageRegistryCredential(server='myregistry.azurecr.io', username='acr_username', password='acr_password')]
group = ContainerGroup(location=resource_group.location,
containers=[container],
os_type=OperatingSystemTypes.linux,
ip_address=group_ip_address,
image_registry_credentials=credentials)
基于 this guide I wrote this sample code,适用于默认图像(“microsoft/aci-helloworld”),但在我的 azure 订阅中更改为来自 Azure 容器注册表的图像时失败。
错误信息是:
The image 'mytest.azurecr.io/myimage:latest' in container group '' is not accessible. Please check the image and registry credential.
我找到了这个
我也试过我的图像名称 with/without “:latest” 后缀,并确保“docker pull mytest.azurecr.io/myimage:latest " 成功。
编辑:添加 ACR 截图:
注意:我也尝试了 C# 代码示例(根据
az ad sp create-for-rbac --sdk-auth > my.azureauth
这是否意味着该服务主体应该有权访问同一订阅中的任何 ACR?
根据我的经验,你得到的错误是图片名错误导致的,说明在ACR中找不到该图片。如屏幕截图所示,图像名称必须是 xxxtestaci.azurecr.io/tempxxx:latest
或 xxxtestaci.azurecr.io/tempxxx
。重现错误也很容易:
而ACR的凭证,可以按照Azure Container Registry authentication with service principals中的步骤进行。但是,如果您在创建资源和从 ACR 中提取图像时仅使用一个服务主体,我建议您向服务主体授予 Contributor
角色。
这是否意味着该服务主体应该有权访问同一订阅中的任何 ACR?
默认情况下,CLI 命令az ad sp create-for-rbac
使用默认参数--role Contributor
。所以是的,它可以访问同一订阅中的任何 ACR。
缺少的部分是添加 ACR 的凭据。固定代码如下所示(您必须在 ImageRegistryCredential 实例中设置服务器、用户名和密码):
credentials = [ImageRegistryCredential(server='myregistry.azurecr.io', username='acr_username', password='acr_password')]
group = ContainerGroup(location=resource_group.location,
containers=[container],
os_type=OperatingSystemTypes.linux,
ip_address=group_ip_address,
image_registry_credentials=credentials)