.Net 标准项目 docker 未找到复制文件 visual studio
.Net standard project docker COPY file not found visual studio
我有一个名为 PrivateSales 的 .Net 标准项目,其 Docker 文件看起来像这样
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:6.0.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
EXPOSE 93
RUN sed -i 's/CipherString = DEFAULT@SECLEVEL=2//' /etc/ssl/openssl.cnf
RUN sed -i 's/MinProtocol = TLSv1.2//' /etc/ssl/openssl.cnf
RUN sed -i 's/[system_default_sect]//' /etc/ssl/openssl.cnf
RUN apt-get update && apt-get install -y libgdiplus
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["PSS.PrivateSalesApi/PSS.PrivateSalesAPI.csproj", "PSS.PrivateSalesApi/"]
RUN dotnet restore "PSS.PrivateSalesApi/PSS.PrivateSalesAPI.csproj"
COPY . .
WORKDIR "/src"
RUN dotnet build "PSS.PrivateSalesApi/PSS.PrivateSalesAPI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "PSS.PrivateSalesApi/PSS.PrivateSalesAPI.csproj" -c Release -o /app/publish
run mkdir Logs
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "PSS.PrivateSalesAPI.dll"]
这是包含 Docker 文件和项目文件的文件夹
link to imgur
当我尝试通过 visual studio 2022(最新版本)使用 Docker-compose 构建 Docker 图像时,COPY 命令失败并出现此错误
#15 [build 3/14] COPY [PSS.PrivateSalesApi/PSS.PrivateSalesAPI.csproj, PSS.PrivateSalesApi/]
2>#15 ERROR: "/PSS.PrivateSalesApi/PSS.PrivateSalesAPI.csproj" not found: not found
2>#13 [build 1/14] FROM mcr.microsoft.com/dotnet/sdk:6.0@sha256:fde93347d1cc74a03f1804f113ce85add00c6f0af15881181165ef04bc76bd00
2>#13 CANCELED
在我昨天将 visual studio 更新到最新版本之前它工作正常。
这是带有错误
的 visual studio 输出
Build started...
1>------ Build started: Project: PSS.PrivateSalesAPI, Configuration: Release Any CPU ------
1>Skipping analyzers to speed up the build. You can execute 'Build' or 'Rebuild' command to run analyzers.
1>PSS.PrivateSalesAPI -> D:\prodev\upwork\mutualart\PSS\PSS.PrivateSalesAPI\bin\Release\net6.0\PSS.PrivateSalesAPI.dll
2>------ Build started: Project: docker-compose, Configuration: Release Any CPU ------
2>D:\prodev\upwork\mutualart\PSS\PSS.PrivateSalesAPI\Services\UserService.cs(191,30,191,32): warning CS0168: The variable 'ex' is declared but never used
2>D:\prodev\upwork\mutualart\PSS\PSS.PrivateSalesAPI\Services\UserService.cs(294,30,294,32): warning CS0168: The variable 'ex' is declared but never used
2>PSS.PrivateSalesAPI -> D:\prodev\upwork\mutualart\PSS\PSS.PrivateSalesAPI\bin\Release\net6.0\PSS.PrivateSalesAPI.dll
2>PSS.PrivateSalesAPI -> D:\prodev\upwork\mutualart\PSS\PSS.PrivateSalesAPI\obj\Release\net6.0\PubTmp\Out\
2>Done building project "PSS.PrivateSalesAPI.csproj".
2>docker-compose -f "D:\prodev\upwork\mutualart\PSS\docker-compose.yml" -f "D:\prodev\upwork\mutualart\PSS\docker-compose.override.yml" -p dockercompose2312513701398597106 --ansi never build
2>#1 [internal] load .dockerignore
2>#1 transferring context: 35B done
2>#1 ...
2>#2 [internal] load build definition from Dockerfile
2>#2 transferring dockerfile: 32B done
2>#2 DONE 0.8s
2>#1 [internal] load .dockerignore
2>#1 DONE 1.1s
2>#3 [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:6.0.0
2>#3 DONE 0.0s
2>#4 [internal] load metadata for mcr.microsoft.com/dotnet/sdk:6.0
2>#4 DONE 1.1s
2>#5 [internal] load build context
2>#5 DONE 0.0s
2>#6 [base 1/6] FROM mcr.microsoft.com/dotnet/aspnet:6.0.0
2>#6 DONE 0.0s
2>#7 [base 5/6] RUN sed -i 's/[system_default_sect]//' /etc/ssl/openssl.cnf
2>#7 CACHED
2>#8 [base 3/6] RUN sed -i 's/CipherString = DEFAULT@SECLEVEL=2//' /etc/ssl/openssl.cnf
2>#8 CACHED
2>#9 [base 2/6] WORKDIR /app
2>#9 CACHED
2>#10 [base 4/6] RUN sed -i 's/MinProtocol = TLSv1.2//' /etc/ssl/openssl.cnf
2>#10 CACHED
2>#11 [base 6/6] RUN apt-get update && apt-get install -y libgdiplus
2>#11 CACHED
2>#12 [final 1/2] WORKDIR /app
2>#12 CACHED
2>#13 [build 1/14] FROM mcr.microsoft.com/dotnet/sdk:6.0@sha256:fde93347d1cc74a03f1804f113ce85add00c6f0af15881181165ef04bc76bd00
2>#13 resolve mcr.microsoft.com/dotnet/sdk:6.0@sha256:fde93347d1cc74a03f1804f113ce85add00c6f0af15881181165ef04bc76bd00
2>#13 resolve mcr.microsoft.com/dotnet/sdk:6.0@sha256:fde93347d1cc74a03f1804f113ce85add00c6f0af15881181165ef04bc76bd00 0.2s done
2>#13 sha256:fde93347d1cc74a03f1804f113ce85add00c6f0af15881181165ef04bc76bd00 2.17kB / 2.17kB done
2>#13 sha256:1ee95620598b9afa3046d356bb7f7863e1602075dd407c790c34d0a9833acc73 2.01kB / 2.01kB done
2>#13 sha256:c74c8a7a6bd2c25ea98ecd1f16bd471b2a8208c6f474ebcba73249d06628114e 7.30kB / 7.30kB done
2>#13 sha256:1fe172e4850f03bb45d41a20174112bc119fbfec42a650edbbd8491aee32e3c3 0B / 31.38MB 0.3s
2>#13 ...
2>#5 [internal] load build context
2>#5 transferring context: 107.37kB 0.2s done
2>#5 DONE 0.7s
2>#13 [build 1/14] FROM mcr.microsoft.com/dotnet/sdk:6.0@sha256:fde93347d1cc74a03f1804f113ce85add00c6f0af15881181165ef04bc76bd00
2>#13 ...
2>#14 [build 2/14] WORKDIR /src
2>#14 CACHED
**2>#15 [build 3/14] COPY [PSS.PrivateSalesApi/PSS.PrivateSalesAPI.csproj, PSS.PrivateSalesApi/]
2>#15 ERROR: "/PSS.PrivateSalesApi/PSS.PrivateSalesAPI.csproj" not found: not found**
2>#13 [build 1/14] FROM mcr.microsoft.com/dotnet/sdk:6.0@sha256:fde93347d1cc74a03f1804f113ce85add00c6f0af15881181165ef04bc76bd00
2>#13 CANCELED
2>failed to solve: failed to compute cache key: "/PSS.PrivateSalesApi/PSS.PrivateSalesAPI.csproj" not found: not found
2>------
2> > [build 3/14] COPY [PSS.PrivateSalesApi/PSS.PrivateSalesAPI.csproj, PSS.PrivateSalesApi/]:
2>------
2>D:\Program Files\Microsoft Visual Studio22\Community\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.VisualStudio.Docker.Compose.targets(518,5): error DT1001: failed to solve: failed to compute cache key: "/PSS.PrivateSalesApi/PSS.PrivateSalesAPI.csproj" not found: not found
2>Done building project "docker-compose.dcproj" -- FAILED.
这里是docker-compose.yml文件的内容
version: '3.9'
services:
pss.privatesalesapi:
networks:
- seqnetwork
container_name: api
image: ${DOCKER_REGISTRY-}pssprivatesalesapi
ports:
- 5000:80
- 5001:443
build:
context: ./
dockerfile: ./PSS.PrivateSalesAPI/Dockerfile
environment:
- ASPNETCORE_ENVIRONMENT=Development
extra_hosts:
- "gql.local:host-gateway"
seq:
networks:
- seqnetwork
container_name: logging
image: datalust/seq:latest
ports:
- 5341:5341
- 5342:80
environment:
- ACCEPT_EULA=Y
seqcli:
image: datalust/seqcli:latest
command: apikey create -t 'dApiKey' --token=eZRR3G1ydnvhFELx8FOQ --server=http://seq -p Environment=Dev --minimum-level=Verbose
restart: on-failure
depends_on:
- seq
networks:
- seqnetwork
networks:
seqnetwork:
driver: bridge
事实证明,Dockerfile 随着更新变得区分大小写。在 Dockerfile 中更改 PrivateSalesApi -> PrivateSalesAPI 解决了我的问题。
我有一个名为 PrivateSales 的 .Net 标准项目,其 Docker 文件看起来像这样
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:6.0.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
EXPOSE 93
RUN sed -i 's/CipherString = DEFAULT@SECLEVEL=2//' /etc/ssl/openssl.cnf
RUN sed -i 's/MinProtocol = TLSv1.2//' /etc/ssl/openssl.cnf
RUN sed -i 's/[system_default_sect]//' /etc/ssl/openssl.cnf
RUN apt-get update && apt-get install -y libgdiplus
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["PSS.PrivateSalesApi/PSS.PrivateSalesAPI.csproj", "PSS.PrivateSalesApi/"]
RUN dotnet restore "PSS.PrivateSalesApi/PSS.PrivateSalesAPI.csproj"
COPY . .
WORKDIR "/src"
RUN dotnet build "PSS.PrivateSalesApi/PSS.PrivateSalesAPI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "PSS.PrivateSalesApi/PSS.PrivateSalesAPI.csproj" -c Release -o /app/publish
run mkdir Logs
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "PSS.PrivateSalesAPI.dll"]
这是包含 Docker 文件和项目文件的文件夹 link to imgur
当我尝试通过 visual studio 2022(最新版本)使用 Docker-compose 构建 Docker 图像时,COPY 命令失败并出现此错误
#15 [build 3/14] COPY [PSS.PrivateSalesApi/PSS.PrivateSalesAPI.csproj, PSS.PrivateSalesApi/]
2>#15 ERROR: "/PSS.PrivateSalesApi/PSS.PrivateSalesAPI.csproj" not found: not found
2>#13 [build 1/14] FROM mcr.microsoft.com/dotnet/sdk:6.0@sha256:fde93347d1cc74a03f1804f113ce85add00c6f0af15881181165ef04bc76bd00
2>#13 CANCELED
在我昨天将 visual studio 更新到最新版本之前它工作正常。 这是带有错误
的 visual studio 输出Build started...
1>------ Build started: Project: PSS.PrivateSalesAPI, Configuration: Release Any CPU ------
1>Skipping analyzers to speed up the build. You can execute 'Build' or 'Rebuild' command to run analyzers.
1>PSS.PrivateSalesAPI -> D:\prodev\upwork\mutualart\PSS\PSS.PrivateSalesAPI\bin\Release\net6.0\PSS.PrivateSalesAPI.dll
2>------ Build started: Project: docker-compose, Configuration: Release Any CPU ------
2>D:\prodev\upwork\mutualart\PSS\PSS.PrivateSalesAPI\Services\UserService.cs(191,30,191,32): warning CS0168: The variable 'ex' is declared but never used
2>D:\prodev\upwork\mutualart\PSS\PSS.PrivateSalesAPI\Services\UserService.cs(294,30,294,32): warning CS0168: The variable 'ex' is declared but never used
2>PSS.PrivateSalesAPI -> D:\prodev\upwork\mutualart\PSS\PSS.PrivateSalesAPI\bin\Release\net6.0\PSS.PrivateSalesAPI.dll
2>PSS.PrivateSalesAPI -> D:\prodev\upwork\mutualart\PSS\PSS.PrivateSalesAPI\obj\Release\net6.0\PubTmp\Out\
2>Done building project "PSS.PrivateSalesAPI.csproj".
2>docker-compose -f "D:\prodev\upwork\mutualart\PSS\docker-compose.yml" -f "D:\prodev\upwork\mutualart\PSS\docker-compose.override.yml" -p dockercompose2312513701398597106 --ansi never build
2>#1 [internal] load .dockerignore
2>#1 transferring context: 35B done
2>#1 ...
2>#2 [internal] load build definition from Dockerfile
2>#2 transferring dockerfile: 32B done
2>#2 DONE 0.8s
2>#1 [internal] load .dockerignore
2>#1 DONE 1.1s
2>#3 [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:6.0.0
2>#3 DONE 0.0s
2>#4 [internal] load metadata for mcr.microsoft.com/dotnet/sdk:6.0
2>#4 DONE 1.1s
2>#5 [internal] load build context
2>#5 DONE 0.0s
2>#6 [base 1/6] FROM mcr.microsoft.com/dotnet/aspnet:6.0.0
2>#6 DONE 0.0s
2>#7 [base 5/6] RUN sed -i 's/[system_default_sect]//' /etc/ssl/openssl.cnf
2>#7 CACHED
2>#8 [base 3/6] RUN sed -i 's/CipherString = DEFAULT@SECLEVEL=2//' /etc/ssl/openssl.cnf
2>#8 CACHED
2>#9 [base 2/6] WORKDIR /app
2>#9 CACHED
2>#10 [base 4/6] RUN sed -i 's/MinProtocol = TLSv1.2//' /etc/ssl/openssl.cnf
2>#10 CACHED
2>#11 [base 6/6] RUN apt-get update && apt-get install -y libgdiplus
2>#11 CACHED
2>#12 [final 1/2] WORKDIR /app
2>#12 CACHED
2>#13 [build 1/14] FROM mcr.microsoft.com/dotnet/sdk:6.0@sha256:fde93347d1cc74a03f1804f113ce85add00c6f0af15881181165ef04bc76bd00
2>#13 resolve mcr.microsoft.com/dotnet/sdk:6.0@sha256:fde93347d1cc74a03f1804f113ce85add00c6f0af15881181165ef04bc76bd00
2>#13 resolve mcr.microsoft.com/dotnet/sdk:6.0@sha256:fde93347d1cc74a03f1804f113ce85add00c6f0af15881181165ef04bc76bd00 0.2s done
2>#13 sha256:fde93347d1cc74a03f1804f113ce85add00c6f0af15881181165ef04bc76bd00 2.17kB / 2.17kB done
2>#13 sha256:1ee95620598b9afa3046d356bb7f7863e1602075dd407c790c34d0a9833acc73 2.01kB / 2.01kB done
2>#13 sha256:c74c8a7a6bd2c25ea98ecd1f16bd471b2a8208c6f474ebcba73249d06628114e 7.30kB / 7.30kB done
2>#13 sha256:1fe172e4850f03bb45d41a20174112bc119fbfec42a650edbbd8491aee32e3c3 0B / 31.38MB 0.3s
2>#13 ...
2>#5 [internal] load build context
2>#5 transferring context: 107.37kB 0.2s done
2>#5 DONE 0.7s
2>#13 [build 1/14] FROM mcr.microsoft.com/dotnet/sdk:6.0@sha256:fde93347d1cc74a03f1804f113ce85add00c6f0af15881181165ef04bc76bd00
2>#13 ...
2>#14 [build 2/14] WORKDIR /src
2>#14 CACHED
**2>#15 [build 3/14] COPY [PSS.PrivateSalesApi/PSS.PrivateSalesAPI.csproj, PSS.PrivateSalesApi/]
2>#15 ERROR: "/PSS.PrivateSalesApi/PSS.PrivateSalesAPI.csproj" not found: not found**
2>#13 [build 1/14] FROM mcr.microsoft.com/dotnet/sdk:6.0@sha256:fde93347d1cc74a03f1804f113ce85add00c6f0af15881181165ef04bc76bd00
2>#13 CANCELED
2>failed to solve: failed to compute cache key: "/PSS.PrivateSalesApi/PSS.PrivateSalesAPI.csproj" not found: not found
2>------
2> > [build 3/14] COPY [PSS.PrivateSalesApi/PSS.PrivateSalesAPI.csproj, PSS.PrivateSalesApi/]:
2>------
2>D:\Program Files\Microsoft Visual Studio22\Community\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.VisualStudio.Docker.Compose.targets(518,5): error DT1001: failed to solve: failed to compute cache key: "/PSS.PrivateSalesApi/PSS.PrivateSalesAPI.csproj" not found: not found
2>Done building project "docker-compose.dcproj" -- FAILED.
这里是docker-compose.yml文件的内容
version: '3.9'
services:
pss.privatesalesapi:
networks:
- seqnetwork
container_name: api
image: ${DOCKER_REGISTRY-}pssprivatesalesapi
ports:
- 5000:80
- 5001:443
build:
context: ./
dockerfile: ./PSS.PrivateSalesAPI/Dockerfile
environment:
- ASPNETCORE_ENVIRONMENT=Development
extra_hosts:
- "gql.local:host-gateway"
seq:
networks:
- seqnetwork
container_name: logging
image: datalust/seq:latest
ports:
- 5341:5341
- 5342:80
environment:
- ACCEPT_EULA=Y
seqcli:
image: datalust/seqcli:latest
command: apikey create -t 'dApiKey' --token=eZRR3G1ydnvhFELx8FOQ --server=http://seq -p Environment=Dev --minimum-level=Verbose
restart: on-failure
depends_on:
- seq
networks:
- seqnetwork
networks:
seqnetwork:
driver: bridge
事实证明,Dockerfile 随着更新变得区分大小写。在 Dockerfile 中更改 PrivateSalesApi -> PrivateSalesAPI 解决了我的问题。