Home > Enterprise >  Unable to run .NET 6 docker 'runtimeconfig.json was not found'
Unable to run .NET 6 docker 'runtimeconfig.json was not found'

Time:01-18

I'm trying to set up my Docker with API in .NET 6 and Angular App which will call that APIs.

I've set my compose file like:

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

All containers goes up except of the API container which returns

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.

By looking for similar questions i've found that i had to set OutputType to exe and add GenerateRuntimeConfigurationFiles tag in csproj but nothing changed i still get the same error.

Here is my 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="Views\Emails\EmailNegozio.cshtml" />
    <Content Remove="Views\Emails\EmailRiepilogo.cshtml" />
  </ItemGroup>

  <ItemGroup>
    <_ContentIncludedByDefault Remove="bundleconfig.json" />
  </ItemGroup>

  <ItemGroup>
    <EmbeddedResource Include="Views\Emails\EmailNegozio.cshtml">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </EmbeddedResource>
    <EmbeddedResource Include="Views\Emails\EmailRiepilogo.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>

And that's my Dockerfile for API

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" ]

CodePudding user response:

One thing that strikes me is that you copy the .csproj file into a /src/src directory which seems wrong. You're aleady in the working directory /src and then you copy the file into a src directory below that. Try changing these lines in your 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"

to this

# 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"
  •  Tags:  
  • Related