在Azure DevOps Pipeline中,将Docker Image任务推送到ACR失败,并带有“未经授权:需要身份验证". [英] Push Docker Image task to ACR fails in Azure DevOps Pipeline with "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 create 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订阅端点(如果配置正确)为您处理auth(如果配置正确)-为您提供服务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
).
这篇关于在Azure DevOps Pipeline中,将Docker Image任务推送到ACR失败,并带有“未经授权:需要身份验证".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!