在Azure DevOps Pipeline中,将Docker Image任务推送到ACR失败,并带有“未经授权:需要身份验证". [英] Push Docker Image task to ACR fails in Azure DevOps Pipeline with "unauthorized: authentication required"

查看:228
本文介绍了在Azure DevOps Pipeline中,将Docker Image任务推送到ACR失败,并带有“未经授权:需要身份验证".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆