[英]Visual Studio: docker build fails when linked files are in the project
I have a .NET 6 Console project that includes 2 binaries as linked files:我有一个 .NET 6 控制台项目,其中包括 2 个二进制文件作为链接文件:
<ItemGroup>
<None Include="..\HFMath\bin\HFMath.dll" Link="HFMath.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\HFMath\bin\libHFMath.so" Link="libHFMath.so">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
I need to deploy it as a docker container.我需要将它部署为 docker 容器。 The Dockerfile scaffolded by Visual Studio is
Visual Studio 搭建的 Dockerfile 是
FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["ConsoleApp1/ConsoleApp1.csproj", "ConsoleApp1/"]
RUN dotnet restore "ConsoleApp1/ConsoleApp1.csproj"
COPY . .
WORKDIR "/src/ConsoleApp1"
RUN dotnet build "ConsoleApp1.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "ConsoleApp1.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ConsoleApp1.dll"]
when I run docker build, I get the following error:当我运行 docker 构建时,我收到以下错误:
#15 1.054 Determining projects to restore...
#15 1.322 All projects are up-to-date for restore.
#15 2.552 /usr/share/dotnet/sdk/6.0.100/Microsoft.Common.CurrentVersion.targets(5100,5): error MSB3030: Could not copy the file "/src/HFMath/bin/libHFMath.so" because it was not found. [/src/ConsoleApp1/ConsoleApp1.csproj]
#15 2.552 /usr/share/dotnet/sdk/6.0.100/Microsoft.Common.CurrentVersion.targets(5100,5): error MSB3030: Could not copy the file "/src/HFMath/bin/HFMath.dll" because it was not found. [/src/ConsoleApp1/ConsoleApp1.csproj]
#15 2.556
#15 2.556 Build FAILED.
I know that docker doesn't support symlinks, but I still need to build the image.我知道 docker 不支持符号链接,但我仍然需要构建图像。 How do I fix this (without changing the .NET project)?
我该如何解决这个问题(不更改 .NET 项目)?
Problem问题
If you have auto generated the Dockerfile
using Visual Studio, it will also have created a .dockerignore
file (usually in the .sln
folder).如果您使用 Visual Studio 自动生成
Dockerfile
,它还将创建一个.dockerignore
文件(通常在.sln
文件夹中)。 That file will contain an entry to exclude **/bin
from the build context.该文件将包含一个从构建上下文中排除
**/bin
的条目。
This means when the COPY. .
这意味着当
COPY. .
COPY. .
executes, it is ignoring the files in any bin
folder执行时,它会忽略任何
bin
文件夹中的文件
Solution解决方案
.dockerignore
file..dockerignore
文件。!HFMath/bin/
- this will tell Docker to NOT ignore the HFMath/bin
folder!HFMath/bin/
- 这将告诉 Docker 不要忽略HFMath/bin
文件夹docker build
command againdocker build
命令
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.