将 Docker Image 任务推送到 ACR 在 Azure 中失败“未经授权:需要身份验证"; [英] Push Docker Image task to ACR fails in Azure "unauthorized: authentication required"
问题描述
推送和映像到 Azure DevOps 管道中的 Azure 容器注册表任务失败.以前的任务执行得很好,即.docker镜像创建成功,登录ACR成功.但是,推送任务失败,结果如下:
Push and image to Azure Container Registry task in Azure DevOps pipeline fails. Previous tasks are executed fine ie. docker image is created and login to ACR is successful. However, push-task fails with the following result:
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 push to that given acr works fine from local command line.
# 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)
推荐答案
从您的构建中删除 docker 登录步骤,docker 任务使用 azure 订阅端点(如果配置正确)为您处理身份验证,如果没有 - 提供您的服务acrpush
的主体权限.
remove the docker login step from your build, docker tasks handle auth for you using azure subscription endpoint (if it is properly configured), if not - give your service principal permissions to acrpush
).
这篇关于将 Docker Image 任务推送到 ACR 在 Azure 中失败“未经授权:需要身份验证";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!