Azure devops CI/CD docker 构建复制失败找不到路径
Azure devops CI/CD docker build COPY Failed Path not found
我在本地 windows 服务器上托管自己的构建代理。
但是,当我尝试使用默认代理或本地代理构建我的 docker 图像时,它无法复制 .cproj 文件。
我想要的是能够在没有错误的情况下构建此映像。
到目前为止我尝试过的是:
- 将工作目录更改为:../、../../ 和 ~/
- Google求解决方案,但这并没有什么结果,因为太具体了什么的。
请注意,它也不适用于 DevOps 本身的代理 (windows-2022)
有谁知道我可能做错了什么或忽略了什么?
目录:
src/Server/DockerFile
src/Server/Server.csproj
以此类推其他 .csproj 文件
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
ENV ASPNETCORE_URLS=https://+:5005;http://+:5006
WORKDIR /app
EXPOSE 5005
EXPOSE 5006
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /
COPY ["src/Server/Server.csproj", "src/Server/"]
COPY ["src/Application/Application.csproj", "src/Application/"]
COPY ["src/Domain/Domain.csproj", "src/Domain/"]
COPY ["src/Shared/Shared.csproj", "src/Shared/"]
COPY ["src/Infrastructure.Shared/Infrastructure.Shared.csproj", "src/Infrastructure.Shared/"]
COPY ["src/Infrastructure/Infrastructure.csproj", "src/Infrastructure/"]
COPY ["src/Client/Client.csproj", "src/Client/"]
COPY ["src/Client.Infrastructure/Client.Infrastructure.csproj", "src/Client.Infrastructure/"]
RUN dotnet restore "src/Server/Server.csproj" --disable-parallel
COPY . .
WORKDIR "src/Server"
RUN dotnet build "Server.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Server.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
WORKDIR /app/Files
WORKDIR /app
ENTRYPOINT ["dotnet", "DeDenDannenburcht.Server.dll"]
我的管道
管道输出
"C:\Program Files\Docker\Docker\resources\bin\docker.exe" build -f F:\agents\_work\s\src\Server\Dockerfile -t dedendannenburcht:166 --label com.azure.dev.image.system.teamfoundationcollectionuri=https://dev.azure.com/JeremiedevosBusiness/ --label com.azure.dev.image.build.sourceversion=ab657210c8696881754f36393adee9da7394ea19 --label image.base.ref.name=mcr.microsoft.com/dotnet/aspnet:6.0 --label image.base.digest=sha256:545da8027d0de13ac88716fc380201f05ad9b4834b5b2fd95eadf277e51318a7 F:\agents\_work\s\src\Server
#1 [internal] load build definition from Dockerfile
#1 sha256:5cec5c1a6e883854d5ef516a04f7fbc4f77cc63f74549820c4d061dbb560e514
#1 transferring dockerfile: 1.31kB done
#1 DONE 0.0s
#2 [internal] load .dockerignore
#2 sha256:8f7ecf610ac80d8ac3c3e64e4de2e264ecf11892bf7afc5ff6debe41dd69161b
#2 transferring context: 2B done
#2 DONE 0.0s
#4 [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:6.0
#4 sha256:ac4494cbca04ddb415c76edcbcc7688784c2a6ea65dd656286c013738aa3b75f
#4 DONE 0.0s
#3 [internal] load metadata for mcr.microsoft.com/dotnet/sdk:6.0
#3 sha256:9eb4f6c3944cfcbfe18b9f1a753c769fc35341309a8d4a21f8937f47e94c712b
#3 DONE 0.1s
#5 [base 1/2] FROM mcr.microsoft.com/dotnet/aspnet:6.0
#5 sha256:50f1ddc10932c4a74c7af5704e931a9489c710faea4f2381fe2380827a900e00
#5 DONE 0.0s
#6 [base 2/2] WORKDIR /app
#6 sha256:bc3cf6c390e5fe0e66017b4845c8fcf3e56c7adac9f514a00c2c986024f377a4
#6 CACHED
#7 [final 1/4] WORKDIR /app
#7 sha256:3baba3edbb555769ad9a49e827de88d7dcc4f72ad6e2b42e576964e4a30eac96
#7 CACHED
#8 [build 1/14] FROM mcr.microsoft.com/dotnet/sdk:6.0@sha256:a3dd4dee05cd1369014244d03b28b602e6a2e1650210dd8633322e00379471ec
#8 sha256:ff704f84298cdcbd6cd764720a2e1a4dcd4b44ff415133896e77ad0c5d908001
#8 resolve mcr.microsoft.com/dotnet/sdk:6.0@sha256:a3dd4dee05cd1369014244d03b28b602e6a2e1650210dd8633322e00379471ec done
#8 sha256:0af6b8199917326984baa1452533da610b46f65bfbc5296c7f81cb72d3beec84 2.01kB / 2.01kB done
#8 sha256:dc243ad423c72b21b838c1362ca152823b0b379a546887d8c47c437357576fb2 7.31kB / 7.31kB done
#8 sha256:664e00cfda3df2ac7370c116f04a17d636fc041b62bdd9a0b88a60b987344269 0B / 136.50MB 0.1s
#8 sha256:a3dd4dee05cd1369014244d03b28b602e6a2e1650210dd8633322e00379471ec 2.17kB / 2.17kB done
#8 sha256:4253139ebd4dcee5f7878254306eb794d0f2a80ee4ca8d085d0b9e507412fb1e 0B / 25.36MB 0.1s
#10 sha256:aa96c6c99b71465c230e63fb1edea0588e2b25c39d6b44fc1381e7cbe48c15d9
#10 ERROR: "/src/Server/Server.csproj" not found: not found
#13 [build 5/14] COPY [src/Shared/Shared.csproj, src/Shared/]
#13 sha256:8fd70ae770f73428f5ff667da9b5080dff2b8035dbeb1247fe9e76d5890ad27d
#13 ERROR: "/src/Shared/Shared.csproj" not found: not found
#16 [build 8/14] COPY [src/Client/Client.csproj, src/Client/]
#16 sha256:33c15418c5097a788d8ef568338206ce45e5fea62b707a2be13c136b28ca43e9
#16 ERROR: "/src/Client/Client.csproj" not found: not found
#15 [build 7/14] COPY [src/Infrastructure/Infrastructure.csproj, src/Infrastructure/]
#15 sha256:4f643811b59a89db4a864a2a40a7ff2cc05709c3b123027874b72ff436af0d56
#15 ERROR: "/src/Infrastructure/Infrastructure.csproj" not found: not found
#17 [build 9/14] COPY [src/Client.Infrastructure/Client.Infrastructure.csproj, src/Client.Infrastructure/]
#17 sha256:b7385969b745977db24f702bc1c8f0b931cd675b9f44e70870ae2d918632e9b3
#17 ERROR: "/src/Client.Infrastructure/Client.Infrastructure.csproj" not found: not found
#14 [build 6/14] COPY [src/Infrastructure.Shared/Infrastructure.Shared.csproj, src/Infrastructure.Shared/]
#14 sha256:f101a94226cbf6f38fe9d908da512ded2bd68070207a6dd5c003d8967252c970
#14 ERROR: "/src/Infrastructure.Shared/Infrastructure.Shared.csproj" not found: not found
#12 [build 4/14] COPY [src/Domain/Domain.csproj, src/Domain/]
#12 sha256:152a7025db6bab6e2e456a9ab7ef8436cc9689411341ea38c362df78a0d058c1
#12 ERROR: "/src/Domain/Domain.csproj" not found: not found
#11 [build 3/14] COPY [src/Application/Application.csproj, src/Application/]
#11 sha256:1760818b73b46bb8ebf75492933a413de08fd2ab7a26cae37de4ae4a5f60b83e
#11 ERROR: "/src/Application/Application.csproj" not found: not found
------
> [build 2/14] COPY [src/Server/Server.csproj, src/Server/]:
------
------
> [build 3/14] COPY [src/Application/Application.csproj, src/Application/]:
------
------
> [build 4/14] COPY [src/Domain/Domain.csproj, src/Domain/]:
------
------
> [build 5/14] COPY [src/Shared/Shared.csproj, src/Shared/]:
------
------
> [build 6/14] COPY [src/Infrastructure.Shared/Infrastructure.Shared.csproj, src/Infrastructure.Shared/]:
------
------
> [build 7/14] COPY [src/Infrastructure/Infrastructure.csproj, src/Infrastructure/]:
------
------
> [build 8/14] COPY [src/Client/Client.csproj, src/Client/]:
------
------
> [build 9/14] COPY [src/Client.Infrastructure/Client.Infrastructure.csproj, src/Client.Infrastructure/]:
------
failed to compute cache key: "/src/Client.Infrastructure/Client.Infrastructure.csproj" not found: not found
##[error]The process 'C:\Program Files\Docker\Docker\resources\bin\docker.exe' failed with exit code 1
Finishing: Build an image
Dockerfile
位于 src\Server
下方。 构建图像 步骤调用 docker build -f .\src\Server\Dockerfile .\src\Server
这将不起作用,因为它在目录树中已经太深了一层。
所以有几种选择:
- 从根目录调用
docker build -f .\src\Server\Dockerfile .
,但使用自定义shell脚本而不是官方构建图像 step - 好像有那种限制。
- 像这样在
Dockerfile
中使用相对路径:
COPY ["../src/Server/Server.csproj", "src/Server/"]
- 移动
Dockerfile
到根目录。
我在本地 windows 服务器上托管自己的构建代理。 但是,当我尝试使用默认代理或本地代理构建我的 docker 图像时,它无法复制 .cproj 文件。
我想要的是能够在没有错误的情况下构建此映像。 到目前为止我尝试过的是:
- 将工作目录更改为:../、../../ 和 ~/
- Google求解决方案,但这并没有什么结果,因为太具体了什么的。
请注意,它也不适用于 DevOps 本身的代理 (windows-2022) 有谁知道我可能做错了什么或忽略了什么?
目录:
src/Server/DockerFile
src/Server/Server.csproj
以此类推其他 .csproj 文件
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
ENV ASPNETCORE_URLS=https://+:5005;http://+:5006
WORKDIR /app
EXPOSE 5005
EXPOSE 5006
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /
COPY ["src/Server/Server.csproj", "src/Server/"]
COPY ["src/Application/Application.csproj", "src/Application/"]
COPY ["src/Domain/Domain.csproj", "src/Domain/"]
COPY ["src/Shared/Shared.csproj", "src/Shared/"]
COPY ["src/Infrastructure.Shared/Infrastructure.Shared.csproj", "src/Infrastructure.Shared/"]
COPY ["src/Infrastructure/Infrastructure.csproj", "src/Infrastructure/"]
COPY ["src/Client/Client.csproj", "src/Client/"]
COPY ["src/Client.Infrastructure/Client.Infrastructure.csproj", "src/Client.Infrastructure/"]
RUN dotnet restore "src/Server/Server.csproj" --disable-parallel
COPY . .
WORKDIR "src/Server"
RUN dotnet build "Server.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Server.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
WORKDIR /app/Files
WORKDIR /app
ENTRYPOINT ["dotnet", "DeDenDannenburcht.Server.dll"]
我的管道
管道输出
"C:\Program Files\Docker\Docker\resources\bin\docker.exe" build -f F:\agents\_work\s\src\Server\Dockerfile -t dedendannenburcht:166 --label com.azure.dev.image.system.teamfoundationcollectionuri=https://dev.azure.com/JeremiedevosBusiness/ --label com.azure.dev.image.build.sourceversion=ab657210c8696881754f36393adee9da7394ea19 --label image.base.ref.name=mcr.microsoft.com/dotnet/aspnet:6.0 --label image.base.digest=sha256:545da8027d0de13ac88716fc380201f05ad9b4834b5b2fd95eadf277e51318a7 F:\agents\_work\s\src\Server
#1 [internal] load build definition from Dockerfile
#1 sha256:5cec5c1a6e883854d5ef516a04f7fbc4f77cc63f74549820c4d061dbb560e514
#1 transferring dockerfile: 1.31kB done
#1 DONE 0.0s
#2 [internal] load .dockerignore
#2 sha256:8f7ecf610ac80d8ac3c3e64e4de2e264ecf11892bf7afc5ff6debe41dd69161b
#2 transferring context: 2B done
#2 DONE 0.0s
#4 [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:6.0
#4 sha256:ac4494cbca04ddb415c76edcbcc7688784c2a6ea65dd656286c013738aa3b75f
#4 DONE 0.0s
#3 [internal] load metadata for mcr.microsoft.com/dotnet/sdk:6.0
#3 sha256:9eb4f6c3944cfcbfe18b9f1a753c769fc35341309a8d4a21f8937f47e94c712b
#3 DONE 0.1s
#5 [base 1/2] FROM mcr.microsoft.com/dotnet/aspnet:6.0
#5 sha256:50f1ddc10932c4a74c7af5704e931a9489c710faea4f2381fe2380827a900e00
#5 DONE 0.0s
#6 [base 2/2] WORKDIR /app
#6 sha256:bc3cf6c390e5fe0e66017b4845c8fcf3e56c7adac9f514a00c2c986024f377a4
#6 CACHED
#7 [final 1/4] WORKDIR /app
#7 sha256:3baba3edbb555769ad9a49e827de88d7dcc4f72ad6e2b42e576964e4a30eac96
#7 CACHED
#8 [build 1/14] FROM mcr.microsoft.com/dotnet/sdk:6.0@sha256:a3dd4dee05cd1369014244d03b28b602e6a2e1650210dd8633322e00379471ec
#8 sha256:ff704f84298cdcbd6cd764720a2e1a4dcd4b44ff415133896e77ad0c5d908001
#8 resolve mcr.microsoft.com/dotnet/sdk:6.0@sha256:a3dd4dee05cd1369014244d03b28b602e6a2e1650210dd8633322e00379471ec done
#8 sha256:0af6b8199917326984baa1452533da610b46f65bfbc5296c7f81cb72d3beec84 2.01kB / 2.01kB done
#8 sha256:dc243ad423c72b21b838c1362ca152823b0b379a546887d8c47c437357576fb2 7.31kB / 7.31kB done
#8 sha256:664e00cfda3df2ac7370c116f04a17d636fc041b62bdd9a0b88a60b987344269 0B / 136.50MB 0.1s
#8 sha256:a3dd4dee05cd1369014244d03b28b602e6a2e1650210dd8633322e00379471ec 2.17kB / 2.17kB done
#8 sha256:4253139ebd4dcee5f7878254306eb794d0f2a80ee4ca8d085d0b9e507412fb1e 0B / 25.36MB 0.1s
#10 sha256:aa96c6c99b71465c230e63fb1edea0588e2b25c39d6b44fc1381e7cbe48c15d9
#10 ERROR: "/src/Server/Server.csproj" not found: not found
#13 [build 5/14] COPY [src/Shared/Shared.csproj, src/Shared/]
#13 sha256:8fd70ae770f73428f5ff667da9b5080dff2b8035dbeb1247fe9e76d5890ad27d
#13 ERROR: "/src/Shared/Shared.csproj" not found: not found
#16 [build 8/14] COPY [src/Client/Client.csproj, src/Client/]
#16 sha256:33c15418c5097a788d8ef568338206ce45e5fea62b707a2be13c136b28ca43e9
#16 ERROR: "/src/Client/Client.csproj" not found: not found
#15 [build 7/14] COPY [src/Infrastructure/Infrastructure.csproj, src/Infrastructure/]
#15 sha256:4f643811b59a89db4a864a2a40a7ff2cc05709c3b123027874b72ff436af0d56
#15 ERROR: "/src/Infrastructure/Infrastructure.csproj" not found: not found
#17 [build 9/14] COPY [src/Client.Infrastructure/Client.Infrastructure.csproj, src/Client.Infrastructure/]
#17 sha256:b7385969b745977db24f702bc1c8f0b931cd675b9f44e70870ae2d918632e9b3
#17 ERROR: "/src/Client.Infrastructure/Client.Infrastructure.csproj" not found: not found
#14 [build 6/14] COPY [src/Infrastructure.Shared/Infrastructure.Shared.csproj, src/Infrastructure.Shared/]
#14 sha256:f101a94226cbf6f38fe9d908da512ded2bd68070207a6dd5c003d8967252c970
#14 ERROR: "/src/Infrastructure.Shared/Infrastructure.Shared.csproj" not found: not found
#12 [build 4/14] COPY [src/Domain/Domain.csproj, src/Domain/]
#12 sha256:152a7025db6bab6e2e456a9ab7ef8436cc9689411341ea38c362df78a0d058c1
#12 ERROR: "/src/Domain/Domain.csproj" not found: not found
#11 [build 3/14] COPY [src/Application/Application.csproj, src/Application/]
#11 sha256:1760818b73b46bb8ebf75492933a413de08fd2ab7a26cae37de4ae4a5f60b83e
#11 ERROR: "/src/Application/Application.csproj" not found: not found
------
> [build 2/14] COPY [src/Server/Server.csproj, src/Server/]:
------
------
> [build 3/14] COPY [src/Application/Application.csproj, src/Application/]:
------
------
> [build 4/14] COPY [src/Domain/Domain.csproj, src/Domain/]:
------
------
> [build 5/14] COPY [src/Shared/Shared.csproj, src/Shared/]:
------
------
> [build 6/14] COPY [src/Infrastructure.Shared/Infrastructure.Shared.csproj, src/Infrastructure.Shared/]:
------
------
> [build 7/14] COPY [src/Infrastructure/Infrastructure.csproj, src/Infrastructure/]:
------
------
> [build 8/14] COPY [src/Client/Client.csproj, src/Client/]:
------
------
> [build 9/14] COPY [src/Client.Infrastructure/Client.Infrastructure.csproj, src/Client.Infrastructure/]:
------
failed to compute cache key: "/src/Client.Infrastructure/Client.Infrastructure.csproj" not found: not found
##[error]The process 'C:\Program Files\Docker\Docker\resources\bin\docker.exe' failed with exit code 1
Finishing: Build an image
Dockerfile
位于 src\Server
下方。 构建图像 步骤调用 docker build -f .\src\Server\Dockerfile .\src\Server
这将不起作用,因为它在目录树中已经太深了一层。
所以有几种选择:
- 从根目录调用
docker build -f .\src\Server\Dockerfile .
,但使用自定义shell脚本而不是官方构建图像 step - 好像有那种限制。 - 像这样在
Dockerfile
中使用相对路径:
COPY ["../src/Server/Server.csproj", "src/Server/"]
- 移动
Dockerfile
到根目录。