'Tag a Docker container as latest in Azure DevOps

I'm trying to build a Docker container and push it to Azure Container Registry. For that, I created this azure-pipeline.yml

# Docker
# Build and push an image to Azure Container Registry
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker

trigger:
- main

resources:
- repo: self

variables:
  # Container registry service connection established during pipeline creation
  dockerRegistryServiceConnection: '...'
  imageRepository: 'mycontainer'
  containerRegistry: 'azuk.azurecr.io'
  dockerfilePath: '$(Build.SourcesDirectory)/dockerfile'
  tag: '$(Build.BuildId)'

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

The pipeline is working. Now, I have another Azure pipeline that build another container but the base is the first container. For this reason, in the Dockerfile in the first line I added

FROM azuk.azurecr.io/mycontainer

When the pipeline starts, I get an error

manifest for ***/mycontainer:latest not found: manifest unknown: manifest tagged by "latest" is not found

I can't find a way to tell the ACR that the last push is the latest version. I saw few posts where they use the property includeLatestTag that doesn't exist anymore

- stage: Build
  displayName: Build image
  jobs:  
  - job: DockerImage
    displayName: Build and push Docker image
    steps:
    - task: Docker@1
      displayName: 'Build the Docker image'
      inputs:
        containerregistrytype: 'Container Registry'
        dockerRegistryEndpoint: 'Docker Hub'
        command: 'Build an image'
        dockerFile: '**/Dockerfile'
        imageName: '$(ImageName)'
        includeLatestTag: true
        useDefaultContext: false
        buildContext: '.'

How can I add the tag latest to the Docker container and push it to the Azure Container Registry via a Azure DevOps pipeline?



Solution 1:[1]

This is working for me Enrico, it overwrites the "latest" version in the repo as well as creates a new independent version based on the BuildID.

Hope it helps...

- task: Docker@2
  displayName: 'Build & Push image to $(container.registry) container registry'
  inputs:
    containerRegistry: '$(container.registry)'
    repository: '$(container.repository)'
    Dockerfile: '**/Dockerfile'
    command: 'buildAndPush'
    tags: |
      latest
      $(Build.BuildId)

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 manneym