gpt4 book ai didi

Azure DevOps 管道 : Cannot find Docker Image when Pushing to Azure Registry, 'tag ***/appname'

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

我们使用自定义 .sh 文件构建 docker 镜像。然后我们想将其推送到我们的 azure 注册表。我们的 azure 管道中有以下步骤:

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

构建成功,如下所示,它在 docker 中注册为 appname:latest ,但是由于某种原因,azure 找不到它,并要求提供带有标签 ***/应用程序名称

/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

我们尝试了不同的标签组合。 azure 在这里期待什么?

最佳答案

看起来您正在单独构建 Docker 镜像。请注意,需要在本地为私有(private)容器注册表标记容器镜像,然后才能推送。正如 Shayki Abramczyk 提到的,您需要使用 containerRegistry 构建镜像。

要解决此问题,您必须使用“docker tag ”命令和特定的私有(private)容器注册表来标记镜像。

例如:

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

此外,您可以在 Azure DevOps 管道中构建和推送 Docker 镜像。以下 YAML 文件供您引用:

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)

当然,您也可以在 Azure DevOps 管道中单独构建推送镜像,如下所示:

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'

关于Azure DevOps 管道 : Cannot find Docker Image when Pushing to Azure Registry, 'tag ***/appname',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73666815/

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