gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 07:38:06 25 4
gpt4 key购买 nike

我正在尝试构建一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com