azure - 在 Azure DevOps 中将 Docker 容器标记为最新

标签 azure docker azure-devops azure-acr

我正在尝试构建一个 Docker 容器并将其推送到 Azure 容器注册表。为此,我创建了这个 azure-pipeline.yml

# Docker
# Build and push an image to Azure Container Registry
# https://learn.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)

管道正在运行。现在,我有另一个 Azure 管道来构建另一个容器,但基础是第一个容器。为此,我在 Dockerfile 的第一行添加了

FROM azuk.azurecr.io/mycontainer

当管道启动时,我收到错误

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

我找不到一种方法来告诉 ACR 最后推送的是最新版本。我看到一些帖子使用了不再存在的属性 includeLatestTag

- 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: '.'

如何将标签 latest 添加到 Docker 容器并通过 Azure DevOps 管道将其推送到 Azure 容器注册表?

最佳答案

这对我来说很有用,Enrico,它会覆盖存储库中的“最新”版本,并根据 BuildID 创建一个新的独立版本。

希望对你有帮助...

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

关于azure - 在 Azure DevOps 中将 Docker 容器标记为最新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71324759/

相关文章:

Azure 缓存 - Microsoft Enterprise Library 5.0 在 Azure 上缓存应用程序 block 如何?

.net - 尝试在Azure管道上部署SQL数据库路径问题

azure - 多级管道未按预期工作

php - 更新 MySQL 时出现迁移问题

azure - 如何处理 Azure 服务总线上的消息正文类型

docker - `docker run` 使用 Golang API(Docker 文档)

python - 无法在容器内启动 selenium 测试,WebDriverException :Chrome failed to start: exited abnormally

docker - Elasticsearch保护连接

azure-devops - Azure DevOps : how to disable CI trigger on a YAML template pipeline?

reactjs - linux azure web 应用程序不显示我的reactjs 应用程序