We are using AZure DevOps Docker v2 tasks for building and pushing our docker images. We are pushing them to Azure Container registry.
First we used buildAndpush command, but because we need some build arguments (not supported by buildAndpush) we needed to split it.
Here is the excerpt from build yaml:
$(imageTag) is set above as example `2019-10_dev_63cf6d0`
....
- task: Docker@2
displayName: DockerBuild
inputs:
command: build
Dockerfile: src/WebApi/Dockerfile.prod
buildContext: src
tags: $(imageTag)
arguments: '--build-arg PAT=$(AzureDevOpsPAT)'
- task: Docker@2
displayName: DockerPush
inputs:
containerRegistry: AzureContainerRegistryDev
repository: eservice
command: push
tags: $(imageTag)
The build task completes successfully. The problem is when push command is running.
We get:
Starting: DockerPush
==============================================================================
Task : Docker
Description : Build or push Docker images, login or logout, or run a Docker command
Version : 2.157.0
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/docker
==============================================================================
/usr/bin/docker push ***/***service:`2019-10_dev_63cf6d0`
The push refers to repository [***/***service]
An image does not exist locally with the tag: ***/***service
##[error]An image does not exist locally with the tag: ***/***service
##[error]The process '/usr/bin/docker' failed with exit code 1
Finishing: DockerPush
It looks like we are missing docker tag command? I checked the log of the buildAndPush task and indeed after it builds the image it tags it and then push it:
Successfully built 0b7e240d0373
Successfully tagged ***/***service:2019-10_dev_7e568d6
/usr/bin/docker push ***/***service:2019-10_dev_7e568d6
I've looked at the source code of the task and it's strange, no evidence of docker tag command. Any ideas?
Ok, I've figure it out. The buildAndPush calls tag in build script, and mine didn't so I changed the docker build task to:
- task: Docker@2
displayName: DockerBuild
inputs:
command: build
Dockerfile: src/WebApi/Dockerfile.prod
buildContext: src
tags: $(imageTag)
arguments: '--build-arg PAT=$(AzureDevOpsPAT) -t $(containerRegistry)/$(imageRepository):$(imageTag)'
And now I am a happy camper :D
What worked for me was to put the registry connection service in the Build task.
What worked for me was to put the registry connection service in the Build task.
Can you elaborate?
@SwyserDev This:
- task: Docker@2
displayName: Build docker image
inputs:
command: build
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection) # <--- add this
tags: |
$(tag)
What worked for me was to put the registry connection service in the Build task.
Make sure you also have the "repository" specified. (I.e. all 3 are needed: repo., reg. & tag)
Most helpful comment
Ok, I've figure it out. The
buildAndPushcalls tag in build script, and mine didn't so I changed the docker build task to:And now I am a happy camper :D