Home > Software design >  Azure devops Pipelines: Cannot find Docker Image when Pushing to Azure Registry, 'tag ***/appna
Azure devops Pipelines: Cannot find Docker Image when Pushing to Azure Registry, 'tag ***/appna

Time:09-13

We build our docker image with a custom .sh file. Then we would like to push it to our azure registry. We have the following step in our azure pipeline:

    - task: Docker@2
      inputs:
        containerRegistry: 'someazureregistry'
        repository: 'appname'
        command: 'push'
        tags: 'latest'

The build is successfull, and as can be seen below it is registered in docker as appname:latest , however for some reason azure does not find it, and asks for an image with the tag ***/appname.

/usr/bin/docker images
/usr/bin/docker push ***/appname:latest
REPOSITORY       TAG         IMAGE ID       CREATED                  SIZE
appname         latest      f1e11b4fc19c   Less than a second ago   680MB
ubuntu           20.04       a0ce5a295b63   7 days ago               72.8MB
...
The push refers to repository [***/appname]
An image does not exist locally with the tag: ***/appname
##[error]An image does not exist locally with the tag: ***/appname

We have tried different combinations of tags. What is azure expecting here?

CodePudding user response:

It looks like you are building the Docker image separately. Please note that the container image needs to be tag locally for the private container registry before it can be pushed. As Shayki Abramczyk mentioned you need to build the image with containerRegistry.

To resolve this issue you must Tag the image using the "docker tag" command with the specific private container registry.

For example:

docker tag image youoregistryhost:port/xxx/image-name:latest

Besides, you can build and push the Docker image together in Azure DevOps pipeline. The following YAML file for your reference:

variables:
  # Container registry service connection established during pipeline creation
  dockerRegistryServiceConnection: 'testacr'
  imageRepository: 'appname'
  containerRegistry: 'xxx.azurecr.io'
  dockerfilePath: '$(Build.SourcesDirectory)/app/Dockerfile'
  tag: 'latest'
  system.debug : true
  
  # Agent VM image name
  vmImageName: 'ubuntu-latest'
   
stages:
- stage: Build
  displayName: Build and push stage
  jobs:  
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)
    steps:
    - task: Docker@2
      displayName: Build and push an image to container registry
      inputs:
        command: buildAndPush
        repository: $(imageRepository)
        dockerfile: $(dockerfilePath)
        containerRegistry: $(dockerRegistryServiceConnection)
        tags: |
          $(tag)

Of course you can also build and push the image separately in Azure DevOps pipeline like this:

stages:
- stage: Build
  displayName: Build and push stage
  jobs:  
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)
    steps:
    - task: Docker@2
      displayName: Build an image for container registry
      inputs:
        containerRegistry: '$(dockerRegistryServiceConnection)'
        repository: '$(imageRepository)'
        command: 'build'
        Dockerfile: '$(dockerfilePath)'
        tags: 'latest'
    - task: Docker@2
      displayName: Push an image to container registry
      inputs:
        containerRegistry: '$(dockerRegistryServiceConnection)'
        repository: '$(imageRepository)'
        command: 'push'
        tags: 'latest'
  • Related