在Azure DevOps管道中将图像推送到Azure容器注册表任务并失败。先前的任务可以很好地执行。创建docker镜像,并成功登录ACR。但是,推送任务失败,结果如下:
unauthorized: authentication required
[error]unauthorized: authentication required
[error]/usr/bin/docker failed with return code: 1
[section]Finishing: Push Docker image
从本地命令行将docker push到给定的acr可以正常工作。
# Docker image
# Build a Docker image to deploy, run, or push to a container registry.
# Add steps that use Docker Compose, tag images, push to a registry, run an image, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- master
pool:
vmImage: 'Ubuntu-16.04'
variables:
imageName: 'renamed:$(build.buildId)'
azureSubscriptionEndpoint: Renamed
azureContainerRegistry: renamed.azurecr.io
steps:
- task: Docker@1
displayName: Build docker image
inputs:
command: Build an image
dockerFile: Dockerfile
imageName: $(imageName)
containerregistrytype: Azure Container Registry
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureContainerRegistry: $(azureContainerRegistry)
- task: Docker@1
displayName: Login to container registry
inputs:
command: login
containerregistrytype: Azure Container Registry
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureContainerRegistry: $(azureContainerRegistry)
dockerFile: Dockerfile
imageName: $(imageName)
- task: Docker@1
displayName: Push Docker image
inputs:
command: Push an image
containerregistrytype: Azure Container Registry
azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
azureContainerRegistry: $(azureContainerRegistry)
imageName: $(imageName)
答案 0 :(得分:1)
在Azure DevOps中使用Azure容器注册表服务连接时,我遇到了同样的问题。
解决方法是在创建Docker Registry Service Connection时不选择“ Azure Container Registry”,而是选择“ Others”。然后,在Azure门户中,在容器注册表上启用admin用户,并使用其中的凭据创建服务连接。
答案 1 :(得分:0)
从构建中删除docker登录步骤,docker任务使用azure订阅端点(如果配置正确)为您处理auth,否则-将您的服务主体权限授予.item
)。
答案 2 :(得分:0)
进入项目设置-->服务连接-->编辑-->重新验证权限
应该解决问题
答案 3 :(得分:0)
就我而言,我用 433 标记我的图像。
例如:<containerRegistryName>.azurecr.io:443/<imageName>
去掉433后,再推,成功了!