'Pull an image from AzureCR using docker task in Azure pipeline

I am trying to pull a docker image from an Azure CR connected via service connection. I was following this guideline https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/docker?view=azure-devops#overview

And although the "pull" is not mentioned in the docs the command was executed in the pipeline. But the image was tried to be pulled from dockerhub and not via the configured service connection.

Can this be fixed somehow? I do not want to expose the AzureCR url in the pull command but want to use the service connection instead.

I am using the task like this

- task: Docker@2
  displayName: Pull image
  inputs:
    command: pull
    containerRegistry: dockerRegistryServiceConnection
    arguments: <imagename>:<tag>

Thank you



Solution 1:[1]

As a workaround, you can use Pull images from ACR task to pull an image from AzureCR.

enter image description here

enter image description here

In yaml pipeline:

enter image description here

enter image description here

- task: azure container registry@1
  inputs:
    ConnectedServiceNameARM: 'xxx'
    ResourceGroupName: 'xxx'
    Azurecontainerregistry: 'xxx'
    dockerimages: 'xxx'

Solution 2:[2]

Without any extensions you can do:

- task: Docker@1
  displayName: "docker pull from ACR"
  inputs:
    azureSubscriptionEndpoint: '<service connection>'
    azureContainerRegistry: <your ACR name>.azurecr.io
    command: pull
    arguments: '<your ACR name>.azurecr.io/<path to your image>:<version>'

For other Docker tasks , like building and pushing, the ACR name is taken from container registry variable. Here I had to be explicit about the ACR name in arguments. Maybe the same would work for Docker@2.

Unfortunately I can only find documentation for Docker@2.

Solution 3:[3]

Here a slightly adapted version for docker task v2:

    - task: Docker@2
      displayName: Docker pull
      inputs:
        command: pull
        containerRegistry: <your-service-connection>
        arguments: <your-repository>.azurecr.io/<your-image>:<your-tag>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2
Solution 3 sl3dg3