azure-pipelinesazure-container-registry

Pull an image from Azure Container Registry using Docker task in Azure pipelines


I am trying to pull a docker image from an Azure Container Registry (ACR) connected via service connection. I was following this guideline https://learn.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 ACR 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>

Solution

  • This worked for me:

    - task: Docker@2
      displayName: Login to registry
      inputs: 
        command: login
        containerRegistry: $(registry) # variable with Service Connection name
    - task: Bash@3
      displayName: Pulling docker image
      inputs:
        targetType: inline
        # docker_registry_name - name of the private repository
        script: |
          docker pull $(docker_registry_name)/$(image_name):$(tag)
    

    I had to add Docker@2 and login. Before that I had an error saying no basic auth credentials.