Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push Docker Image task to ACR fails in Azure "unauthorized: authentication required"

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 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://learn.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)
like image 473
villekr Avatar asked Apr 03 '19 12:04

villekr


3 Answers

I had the same issue when I used an Azure Container Registry Service Connection in Azure DevOps.

The work around was to not choose ‘Azure Container Registry’ when creating the Docker Registry Service Connection and to instead choose ‘Others’. Then in the Azure Portal enable admin user on your container registry and use the credentials from that to create the service connection.

like image 118
Steve Avatar answered Nov 20 '22 17:11

Steve


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).

like image 5
4c74356b41 Avatar answered Nov 20 '22 17:11

4c74356b41


I had this issue when pushing a docker image to Azure Container Registry.

I get the error

unauthorized: authentication required, visit https://aka.ms/acr/authorization for more information.

Here's how I fixed it:

My user already had the Owner role to the Container Registry so I had the permission to push and pull images.

The issue was that the admin_user was not enabled in the Azure Container Registry.

All I had to do was to enable the admin user. This generates a username, password, and password2.

enter image description here

Next, you can log in now to Azure Container Registry using the command:

az acr login --name my-container-registry

Tag your docker image

docker tag image-name:image-tag my-container-registry.azurecr.io/image-name:image-tag

And now push image to Azure Container Registry using the command:

docker push my-container-registry.azurecr.io/image-name:image-tag

That's all

like image 4
Promise Preston Avatar answered Nov 20 '22 17:11

Promise Preston