invalid from flag value build: pull access denied for build, repository does not exist or may require 'docker login'

11/25/2019

I am trying to build a simple docker console project at azure DevOps pipeline, but i am unable to build the project.

When i try to copy the code i get this error:

invalid from flag value build: pull access denied for build, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

Here the full docker file:

FROM mcr.microsoft.com/dotnet/core/runtime:2.2-nanoserver-1809 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:2.2-nanoserver-1809 AS build
WORKDIR /src
COPY --from=build "ConsoleApp/ConsoleApp.csproj", "ConsoleApp/" #throws the error here. I added --from=build parameter because it couldn't find the project file.
RUN dotnet restore "ConsoleApp/ConsoleApp.csproj"
COPY . .
WORKDIR "/src/ConsoleApp"
RUN dotnet build "ConsoleApp.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "ConsoleApp.csproj" -c Release -o /app/publish

FROM base AS final 
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ConsoleApp.dll"]

Update:

The task yml file:

steps:
- task: Docker@0
  displayName: 'Build an image'
  inputs:
    containerregistrytype: 'Container Registry'
    dockerRegistryConnection: 'doker hub'

Update 2:

I changed copy command to COPY . .

The file path, at TFS is:

enter image description here

The complete log file:

2019-11-25T15:34:33.4491101Z ##[section]Starting: Build an image
2019-11-25T15:34:33.4613318Z ==============================================================================
2019-11-25T15:34:33.4613432Z Task         : Docker
2019-11-25T15:34:33.4613528Z Description  : Build, tag, push, or run Docker images, or run a Docker command
2019-11-25T15:34:33.4613620Z Version      : 0.157.0
2019-11-25T15:34:33.4613689Z Author       : Microsoft Corporation
2019-11-25T15:34:33.4613787Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/docker
2019-11-25T15:34:33.4613868Z ==============================================================================
2019-11-25T15:34:34.0099201Z dbef9fd1-06fb-47eb-af36-bf86b4d44152 exists true
2019-11-25T15:34:34.1132072Z [command]"C:\Program Files\Docker\docker.exe" build -f d:\a\8\s\AppTest\ConsoleApp\Dockerfile -t azuretp:33 d:\a\8\s\AppTest\ConsoleApp
2019-11-25T15:34:39.3835392Z Sending build context to Docker daemon  11.26kB
2019-11-25T15:34:39.3835994Z 
2019-11-25T15:34:39.5250901Z Step 1/16 : FROM mcr.microsoft.com/dotnet/core/runtime:2.2-nanoserver-1809 AS base
2019-11-25T15:34:39.6690789Z 2.2-nanoserver-1809: Pulling from dotnet/core/runtime
2019-11-25T15:34:39.7397363Z 23bc016eaf5f: Pulling fs layer
2019-11-25T15:34:39.7477118Z 1506a91e0e91: Pulling fs layer
2019-11-25T15:34:39.7477672Z d752defd04f4: Pulling fs layer
2019-11-25T15:34:39.7477814Z 5b76cf9aff11: Pulling fs layer
2019-11-25T15:34:39.7477937Z 1fae94ecbbe0: Pulling fs layer
2019-11-25T15:34:39.7478049Z e2843b29b78d: Pulling fs layer
2019-11-25T15:34:39.7625929Z 5b76cf9aff11: Waiting
2019-11-25T15:34:39.7626564Z 1fae94ecbbe0: Waiting
2019-11-25T15:34:39.7626924Z e2843b29b78d: Waiting
2019-11-25T15:34:39.8306380Z d752defd04f4: Verifying Checksum
2019-11-25T15:34:39.8313518Z d752defd04f4: Download complete
2019-11-25T15:34:39.9793967Z 5b76cf9aff11: Verifying Checksum
2019-11-25T15:34:39.9794591Z 5b76cf9aff11: Download complete
2019-11-25T15:34:40.0818943Z 1fae94ecbbe0: Verifying Checksum
2019-11-25T15:34:40.0821242Z 1fae94ecbbe0: Download complete
2019-11-25T15:34:40.1914033Z e2843b29b78d: Verifying Checksum
2019-11-25T15:34:40.1915182Z e2843b29b78d: Download complete
2019-11-25T15:34:40.2091921Z 1506a91e0e91: Verifying Checksum
2019-11-25T15:34:40.2093781Z 1506a91e0e91: Download complete
2019-11-25T15:34:41.1068042Z 23bc016eaf5f: Verifying Checksum
2019-11-25T15:34:41.1070095Z 23bc016eaf5f: Download complete
2019-11-25T15:35:08.7208576Z 23bc016eaf5f: Pull complete
2019-11-25T15:35:11.7597259Z 1506a91e0e91: Pull complete
2019-11-25T15:35:12.0753094Z d752defd04f4: Pull complete
2019-11-25T15:35:13.5034462Z 5b76cf9aff11: Pull complete
2019-11-25T15:35:13.7952825Z 1fae94ecbbe0: Pull complete
2019-11-25T15:35:14.3030594Z e2843b29b78d: Pull complete
2019-11-25T15:35:14.3385623Z Digest: sha256:6a11ceb844e0298386926e5b6d9fb8ca08b48b3142714084f9a519ce76772b8b
2019-11-25T15:35:14.3591831Z Status: Downloaded newer image for mcr.microsoft.com/dotnet/core/runtime:2.2-nanoserver-1809
2019-11-25T15:35:14.3605675Z  ---> a6fac7758a94
2019-11-25T15:35:14.3606063Z Step 2/16 : WORKDIR /app
2019-11-25T15:35:14.4148679Z  ---> Running in fd199c77b02c
2019-11-25T15:35:16.4898262Z Removing intermediate container fd199c77b02c
2019-11-25T15:35:16.4898928Z  ---> 559e8e328061
2019-11-25T15:35:16.4900006Z Step 3/16 : FROM mcr.microsoft.com/dotnet/core/sdk:2.2-nanoserver-1809 AS build
2019-11-25T15:35:16.5504979Z 2.2-nanoserver-1809: Pulling from dotnet/core/sdk
2019-11-25T15:35:16.6323512Z 23bc016eaf5f: Already exists
2019-11-25T15:35:16.6548830Z 37495ddaa8b9: Pulling fs layer
2019-11-25T15:35:16.6549322Z fb2660aea92f: Pulling fs layer
2019-11-25T15:35:16.6549732Z 3471d6e268de: Pulling fs layer
2019-11-25T15:35:16.6549818Z 947e8b97bb92: Pulling fs layer
2019-11-25T15:35:16.6549882Z 8b9c86e8b548: Pulling fs layer
2019-11-25T15:35:16.6549973Z bbd5e542a7a2: Pulling fs layer
2019-11-25T15:35:16.6550036Z 8b9c86e8b548: Waiting
2019-11-25T15:35:16.6550121Z bbd5e542a7a2: Waiting
2019-11-25T15:35:16.6550182Z 947e8b97bb92: Waiting
2019-11-25T15:35:16.7268050Z 3471d6e268de: Download complete
2019-11-25T15:35:16.7989518Z fb2660aea92f: Verifying Checksum
2019-11-25T15:35:16.7990139Z fb2660aea92f: Download complete
2019-11-25T15:35:16.8097265Z 947e8b97bb92: Verifying Checksum
2019-11-25T15:35:16.8097696Z 947e8b97bb92: Download complete
2019-11-25T15:35:16.8796696Z 8b9c86e8b548: Verifying Checksum
2019-11-25T15:35:16.8797664Z 8b9c86e8b548: Download complete
2019-11-25T15:35:18.3468013Z 37495ddaa8b9: Verifying Checksum
2019-11-25T15:35:18.3468807Z 37495ddaa8b9: Download complete
2019-11-25T15:35:19.4024655Z bbd5e542a7a2: Verifying Checksum
2019-11-25T15:35:19.4035569Z bbd5e542a7a2: Download complete
2019-11-25T15:35:35.6503063Z 37495ddaa8b9: Pull complete
2019-11-25T15:35:36.9309676Z fb2660aea92f: Pull complete
2019-11-25T15:35:39.3216403Z 3471d6e268de: Pull complete
2019-11-25T15:35:40.4185198Z 947e8b97bb92: Pull complete
2019-11-25T15:35:40.4185427Z 8b9c86e8b548: Pull complete
2019-11-25T15:37:22.5830397Z bbd5e542a7a2: Pull complete
2019-11-25T15:37:22.6176806Z Digest: sha256:8e4d25caa7e31a29b65baf74bd98409dd726bafd01a6233ae0fe40ec9f674483
2019-11-25T15:37:22.6437483Z Status: Downloaded newer image for mcr.microsoft.com/dotnet/core/sdk:2.2-nanoserver-1809
2019-11-25T15:37:22.6448181Z  ---> 7be0da52b85b
2019-11-25T15:37:22.6448641Z Step 4/16 : WORKDIR /src
2019-11-25T15:37:22.6918329Z  ---> Running in 7fdf9cdde20c
2019-11-25T15:37:24.1326749Z Removing intermediate container 7fdf9cdde20c
2019-11-25T15:37:24.1327772Z  ---> 1da4399c5ac8
2019-11-25T15:37:24.1328334Z Step 5/16 : CMD dir /s *.*
2019-11-25T15:37:24.1731384Z  ---> Running in cffc4fb91ebd
2019-11-25T15:37:25.0149409Z Removing intermediate container cffc4fb91ebd
2019-11-25T15:37:25.0150113Z  ---> 0f83603380ce
2019-11-25T15:37:25.0156828Z Step 6/16 : COPY . .
2019-11-25T15:37:25.8923312Z  ---> b7d0a7c26ab3
2019-11-25T15:37:25.8924095Z Step 7/16 : RUN dotnet restore "ConsoleApp/ConsoleApp.csproj"
2019-11-25T15:37:25.9551579Z  ---> Running in fcad63d07491
2019-11-25T15:37:28.4525972Z MSBUILD : error MSB1009: Project file does not exist.
2019-11-25T15:37:28.4526602Z Switch: ConsoleApp/ConsoleApp.csproj
2019-11-25T15:37:29.4257288Z The command 'cmd /S /C dotnet restore "ConsoleApp/ConsoleApp.csproj"' returned a non-zero code: 1
2019-11-25T15:37:29.4499158Z ##[error]C:\Program Files\Docker\docker.exe failed with return code: 1
2019-11-25T15:37:29.4552631Z ##[section]Finishing: Build an image
-- MiguelSlv
azure-devops
azure-kubernetes
azure-pipelines
devops
visual-studio

2 Answers

11/29/2019

Solve it by removing the project file from all the dotnet commands.

Bellow the final dockerfile:

COPY . ./
RUN dotnet restore   
RUN dotnet build  -c Release -o /app/build

FROM build AS publish
RUN dotnet publish -c Release -o /app/publish

FROM base AS final 
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ConsoleApp.dll"]
-- MiguelSlv
Source: StackOverflow

11/25/2019

I think that this error is because you are trying to copy something from "build" image that does not exist.

The first parameter in "COPY" command, is the local path inside the agent. And the second parameter, is where you want to copy the content inside the docker image

Delete "--from=build" and run again.

Or you can use this dockerfile that I wrote for you. It will make the same Image you want with less steps.

FROM mcr.microsoft.com/dotnet/core/runtime:2.2-nanoserver-1809 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:2.2-nanoserver-1809 AS build
WORKDIR /src
COPY . .
WORKDIR "/src/ConsoleApp"
RUN dotnet build "ConsoleApp.csproj" -c Release
RUN dotnet publish "ConsoleApp.csproj" -c Release --no-restore --no-build -o /app/publish

FROM base AS final 
WORKDIR /app
COPY --from=build /app/publish .
ENTRYPOINT ["dotnet", "ConsoleApp.dll"]

UPDATE

Check the Docker Hub connection. Update the credentials and try again. To give you a better answer, could you share the build log?

UPDATE 2

Your dockerfile is inside ConsoleApp folder. So, the COPY will ignore the root folder. Change the COPY cmd to COPY . ./ConsoleApp

-- joaoigm
Source: StackOverflow