question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Docker v2 separate build and push task issue

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

7reactions
mihajcommented, Oct 10, 2019

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 😄

4reactions
josmarecommented, Oct 16, 2019

What worked for me was to put the registry connection service in the Build task.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Docker@2 - Docker v2 task - Microsoft Learn
A Docker task configured using the buildAndPush command ignores the arguments passed because they become ambiguous to the internal build and ...
Read more >
Seperate build and push without defining containerRegistry in ...
My question is: How can I do this within azure devops without having to define the "containerRegistry" in the build task? The problem...
Read more >
Multi-stage builds - Docker Documentation
With multi-stage builds, you use multiple FROM statements in your Dockerfile. Each FROM instruction can use a different base, and each of them...
Read more >
Using –build-args with docker in Azure DevOps Pipelines
The background around this problem is that I want to add in some ... task: Docker@2 displayName: 'Build and Push Docker Image' inputs: ......
Read more >
Pipeline Docker Task Build & Push fails to push image to ...
Pushing an image from command line on a remote machine after docker login works, so I think is not a credentials o registry...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found