Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pushing docker image to Docker Hub from Azure DevOps pipeline

I have a .Net core web application with a Dockerfile.

I am using Azure DevOps pipeline to build the docker image, and want to push that image on Docker Hub.

But when I run the pipeline, it fails while pushing image with below error:

2019-07-25T07:40:39.2332684Z ##[section]Starting: Push an image
2019-07-25T07:40:39.2340807Z ==============================================================================
2019-07-25T07:40:39.2340932Z Task         : Docker
2019-07-25T07:40:39.2341017Z Description  : Build, tag, push, or run Docker images, or run a Docker command
2019-07-25T07:40:39.2341132Z Version      : 0.154.1
2019-07-25T07:40:39.2341206Z Author       : Microsoft Corporation
2019-07-25T07:40:39.2341308Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/docker
2019-07-25T07:40:39.2341405Z ==============================================================================
2019-07-25T07:40:39.4058071Z e6868ba4-0951-4724-b13b-58e178dacb79 exists true
2019-07-25T07:40:39.5494209Z [command]/usr/bin/docker push dockerDemo2019:19
2019-07-25T07:40:39.5780069Z The push refers to repository [docker.io/library/dockerDemo2019]
2019-07-25T07:40:40.5429692Z b0f339cf7b16: Preparing
2019-07-25T07:40:40.5430778Z a385a9a129e2: Preparing
2019-07-25T07:40:40.5431098Z 6339615de93e: Preparing
2019-07-25T07:40:40.5431279Z c6c9de941dfa: Preparing
2019-07-25T07:40:40.5431433Z 9c894eb0930b: Preparing
2019-07-25T07:40:40.5431696Z d56055da3352: Preparing
2019-07-25T07:40:40.5431855Z d56055da3352: Waiting
2019-07-25T07:40:42.4737943Z denied: requested access to the resource is denied
2019-07-25T07:40:42.4880225Z ##[error]denied: requested access to the resource is denied
2019-07-25T07:40:42.4932585Z ##[error]/usr/bin/docker failed with return code: 1
2019-07-25T07:40:42.4960825Z ##[section]Finishing: Push an image

My pipeline setup:

enter image description here

I have verified Dockerregistry service connection and it is connected with dockerhub credential.

like image 505
Amit Kumar Avatar asked Jul 25 '19 09:07

Amit Kumar


People also ask

How do I push Docker image to Docker Hub using Azure DevOps?

From the Configure tab, select the Docker - Build and push an image to Azure Container Registry task. Select your Azure Subscription, and then select Continue. Select your Container registry from the dropdown menu, and then provide an Image Name to your container image. Select Validate and configure when you are done.

How do I deploy a Docker image using Azure DevOps?

Sign in to your Azure DevOps organization and navigate to your project. Select Pipelines, and then New Pipeline. Select GitHub when prompted for the location of your source code, and then select your repository. Select the Docker: build and push an image to Azure Container Registry pipeline template.

How do I publish a Docker image as an artifact in Azure DevOps?

Steps: Add task docker->switch the task version to 0->select the option Run a Docker command , then we could run the docker save command, check the pic below. Is there any better way of doing this apart from saving an image. We recommend that you use this to upload the docker image as an artifact. Save this answer.


2 Answers

You need to switch the Docker task version from 0.* to 2.*.

Then you need to define also your Docker hub repository name:

enter image description here

enter image description here

The same thing you need to do also in the build step - switch to 2.* and define the repository name.

By the way - in the 2.* version, the action name is buildAndPush, which combines both the build and push tasks.

like image 167
Shayki Abramczyk Avatar answered Oct 04 '22 22:10

Shayki Abramczyk


My Service Connection was the issue in my case . I messed it up as the default was "Others" .

After setting the Registry Type to DockerHub and subsequently setting up credentials , it worked fine .

Ofcourse the steps suggested by [![https://stackoverflow.com/users/7409220/shayki-abramczyk] were important too .

enter image description here

like image 20
Rajesh Rajamani Avatar answered Oct 04 '22 21:10

Rajesh Rajamani