[英]Azure DevOps Pipelines push Docker image to Container Registry Denied
[英]Azure devops Pipelines: Cannot find Docker Image when Pushing to Azure Registry, 'tag ***/appname'
我們使用 custom.sh 文件構建 docker 映像。 然后我們想將它推送到我們的 azure 注冊表。 我們的 azure 管道中有以下步驟:
- task: Docker@2
inputs:
containerRegistry: 'someazureregistry'
repository: 'appname'
command: 'push'
tags: 'latest'
構建成功,如下所示,它在 docker 中注冊為appname:latest
,但是由於某種原因 azure 找不到它,並要求提供帶有標簽***/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
我們嘗試了不同的標簽組合。 azure 在這里期待什么?
看起來您正在單獨構建 Docker 映像。 請注意,容器鏡像需要在本地為私有容器注冊表打標簽,然后才能推送。 正如 Shayki Abramczyk 提到的,您需要使用containerRegistry
構建映像。
要解決此問題,您必須使用帶有特定私有容器注冊表的“ docker tag ”命令標記圖像。
例如:
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 管道中單獨build
和push
鏡像:
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'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.