You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure容器应用部署报错:Azure容器注册表认证失败

解决Azure Container Apps部署ACR镜像的认证错误

问题现象

执行az containerapp update命令或使用Azure DevOps的AzureContainerApps@1任务部署ACR镜像时,返回如下认证错误:

ERROR: (InvalidParameterValueInContainerTemplate) The following field(s) are either invalid or missing. Field 'template.containers..image' is invalid with details: 'Invalid value: ".azurecr.io/:20240430.13": GET https:?scope=repository%3A%3Apull&service=.azurecr.io: UNAUTHORIZED: authentication required...'

解决方案

1. 确认ACR资源级权限配置

即使服务连接拥有订阅级完全权限,也需确保权限直接分配到ACR资源上:

  • 执行以下命令检查服务主体在ACR上的权限:
    az role assignment list --assignee <service-principal-id> --scope /subscriptions/<subscription-id>/resourceGroups/<rg-name>/providers/Microsoft.ContainerRegistry/registries/<acr-name>
    
  • 若未找到AcrPull权限,手动分配:
    az role assignment create --assignee <service-principal-id> --role AcrPull --scope /subscriptions/<subscription-id>/resourceGroups/<rg-name>/providers/Microsoft.ContainerRegistry/registries/<acr-name>
    

2. 验证ACR登录与令牌生成

  • 用具备ACR管理员权限的账号执行登录命令,确认可正常访问:
    az acr login --name <containerRegistry>
    
  • 尝试生成拉取专用令牌:
    az acr token create --name acr-pull-token --registry <containerRegistry> --scope-map _repositories_pull
    
    若之前生成令牌返回空,需检查当前账号是否有ACR的Container Registry Contributor或更高权限。

3. 检查Container App的认证配置

  • 如果使用托管标识访问ACR:
    1. 为Container App启用系统分配或用户分配托管标识
    2. 给该标识分配ACR的AcrPull权限(命令同步骤1)
    3. 更新Container App配置,指定使用托管标识拉取镜像:
      az containerapp update -n <appName> -g <rg-name> --registry-server <containerRegistry>.azurecr.io --identity <managed-identity-id>
      

4. 排查网络与CLI兼容性

  • 若ACR配置了防火墙/私有网络,需确保Container Apps环境的虚拟网络允许访问ACR(配置VNet对等连接或添加Container App出站IP到ACR防火墙白名单)
  • 升级Azure CLI到最新版本,避免兼容性问题:
    az upgrade --yes
    

5. 验证Azure DevOps任务参数

确认AzureContainerApps@1任务的acrName参数正确填写ACR名称,imageToDeploy格式为<acr-name>.azurecr.io/<repo>:<tag>,无拼写错误。

内容的提问来源于stack exchange,提问作者Aaron Jonk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 00:06:10