visual-studio - 无效的标志值构建 : pull access denied for build, 存储库不存在或可能需要 'docker login'

标签 visual-studio azure-devops azure-pipelines devops azure-aks

我正在尝试在 azure DevOps 管道中构建一个简单的 docker 控制台项目,但我无法构建该项目。

当我尝试复制代码时,出现此错误:

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



这里是完整的 docker 文件:
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"]

更新:

任务 yml 文件:
steps:
- task: Docker@0
  displayName: 'Build an image'
  inputs:
    containerregistrytype: 'Container Registry'
    dockerRegistryConnection: 'doker hub'

更新 2:

我将复制命令更改为 COPY . .
TFS 的文件路径是:

enter image description here

完整的日志文件:
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

最佳答案

我遇到了同样的问题,this comment给了我一个答案。看起来这也是你的情况。
问题出在 COPY --from=build指令 - 它引用了 build阶段同时修改 build阶段。

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

# in "base" stage  
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-nanoserver-1809 AS build
WORKDIR /src

# in "build" stage - below command will fail, it could only reference "base" stage
COPY --from=build "ConsoleApp/ConsoleApp.csproj", "ConsoleApp/" 
...
build 开始解决问题阶段,然后在构建 base 时复制您的文件阶段。
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-nanoserver-1809 AS build
WORKDIR /app

# in "build" stage  
FROM mcr.microsoft.com/dotnet/core/runtime:2.2-nanoserver-1809 AS base
WORKDIR /src

# in "base" stage - not you can reference "build" stage
COPY --from=build "/app/ConsoleApp/ConsoleApp.csproj", "ConsoleApp/" 
...

关于visual-studio - 无效的标志值构建 : pull access denied for build, 存储库不存在或可能需要 'docker login',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59034633/

相关文章:

c# - 这是定期异步下载的好代码吗?

c++ - 将位解压缩为单精度 float 的最快方法

azure - 如何在 azure (AKS) 中的 Kubernetes 集群中附加磁盘

azure-devops - 如何在 Azure DevOps 上的发布管道中添加槽位交换任务之前的批准

azure - Azure Release Pipeline的下载结果

linux - VSTS 通过 SSH 复制文件到远程机器

c# - StartPosition 设置为 CenterPosition 但我的表格没有居中

windows - 适用于 Android 的 Visual Studio 模拟器不工作

c# - 检索 Azure DevOps REST API 5.1 的 Accesstoken