无法运行 .NET 6 docker 'runtimeconfig.json is found



我正在尝试在.NET 6和Angular App中使用API设置Docker,Angular App将调用这些API。

我已经将我的合成文件设置为:

version: "3"
services: 
proxy:
build: 
context: ./Proxy
dockerfile: Dockerfile
ports: 
- "8080:80"
restart: always
client:
build:
context: E:AngularVisualOrder
dockerfile: Dockerfile
ports: 
- "9000:80"
api:
build: 
context: E:VisualStudioVisual Studio 2022VisualOrder
dockerfile: Dockerfile
ports: 
- "4201:80"

除了返回的API容器外,所有容器都会上升

A fatal error was encountered. The library 'libhostpolicy.so' required to execute the application was not found in '/app/'.
Failed to run as a self-contained app.
- The application was run as a self-contained app because '/app/VisualOrder.runtimeconfig.json' was not found.
- If this should be a framework-dependent app, add the '/app/VisualOrder.runtimeconfig.json' file and specify the appropriate framework.

通过查找类似的问题,我发现我不得不将OutputType设置为exe,并在csproj中添加GenerateRuntimeConfigurationFiles标记,但没有任何更改,我仍然会得到相同的错误。

这是我的csproj

<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<SignAssembly>false</SignAssembly>
<UserSecretsId>d96c762d-ae98-4b1d-a27d-af48bb400d26</UserSecretsId>
<OutputType>Exe</OutputType>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
</PropertyGroup>
<ItemGroup>
<Content Remove="bundleconfig.json" />
<Content Remove="ViewsEmailsEmailNegozio.cshtml" />
<Content Remove="ViewsEmailsEmailRiepilogo.cshtml" />
</ItemGroup>
<ItemGroup>
<_ContentIncludedByDefault Remove="bundleconfig.json" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="ViewsEmailsEmailNegozio.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="ViewsEmailsEmailRiepilogo.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="bundleconfig.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
<PackageReference Include="MySql.Data" Version="8.0.27" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="PayPalCheckoutSdk" Version="1.0.4" />
<PackageReference Include="PayPalHttp" Version="1.0.1" />
<PackageReference Include="QRCoder" Version="1.4.2" />
<PackageReference Include="RazorEngine.NetCore" Version="3.1.0" />
<PackageReference Include="RestSharp" Version="106.13.0" />
<PackageReference Include="Stripe.net" Version="39.80.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
</Project>

这是我为API 编写的Dockerfile

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
# copy all the layers' csproj files into respective folders
COPY ["VisualOrder.csproj", "src/"]
# run restore over API project - this pulls restore over the dependent projects as well
RUN dotnet restore "src/VisualOrder.csproj"
COPY . .
# run build over the API project
WORKDIR "/src/"
RUN dotnet build -c Release -o /app/build
# run publish over the API project
FROM build AS publish
RUN dotnet publish -c Release -o /app/publish
FROM base AS runtime
WORKDIR /app
COPY --from=publish /app/publish .
RUN ls -l
ENTRYPOINT [ "dotnet", "VisualOrder.dll" ]

让我印象深刻的一件事是,您将.csproj文件复制到/src/src目录中,这似乎是错误的。您在工作目录/src中,然后将文件复制到其下的src目录中。尝试更改你的dockerfile 中的这些行

# copy all the layers' csproj files into respective folders
COPY ["VisualOrder.csproj", "src/"]
# run restore over API project - this pulls restore over the dependent projects as well
RUN dotnet restore "src/VisualOrder.csproj"

到这个

# copy all the layers' csproj files into respective folders
COPY ["VisualOrder.csproj", "."]
# run restore over API project - this pulls restore over the dependent projects as well
RUN dotnet restore "VisualOrder.csproj"

最新更新