Docker multi-stage builds with .NET Core 2.0 fail because of missing dll:s

536 views Asked by At

I have a .NET Core web app generated by dotnet new web -o foo, and the following (multi-stage) Dockerfile:

FROM microsoft/dotnet:2.0-sdk AS builder

WORKDIR /build

COPY ./foo/foo.csproj .
RUN dotnet restore

COPY ./foo/*.cs ./
RUN dotnet publish --configuration Release --output ./app

FROM microsoft/dotnet:2.0-runtime

WORKDIR /app

COPY --from=builder /build/app/* ./

ENTRYPOINT ["dotnet", "./foo.dll"]

Building the image works fine, but running it does not:

PS> docker build . -t foo
# ...
Successfully built <hash>
Successfully tagged foo:latest
PS> docker run --rm foo
Error:
  An assembly specified in the application dependencies manifest (foo.deps.json) was not found:
    package: 'Microsoft.ApplicationInsights.AspNetCore', version: '2.1.1'
    path: 'lib/netstandard1.6/Microsoft.ApplicationInsights.AspNetCore.dll'
  This assembly was expected to be in the local runtime store as the application was published using the following target manifest files:
    aspnetcore-store-2.0.0-linux-x64.xml;aspnetcore-store-2.0.0-osx-x64.xml;aspnetcore-store-2.0.0-win7-x64.xml;aspnetcore-store-2.0.0-win7-x86.xml

It seems that not all required assets are published to the output directory; what more do I have to do to make this work?

1

There are 1 answers

0
herm On

There is a github issue and another on the same problem one solution is:

The ASP.NET Core runtime store is not included in the "runtime only" image. You need to use microsoft/aspnetcore:2.0.0 instead, or opt out of the runtime store trimming.

If you want a smaller image and can change the code you can do:

or (2) disable the publish-time trimming so that your dependencies assemblies are copied into your published output.

<PropertyGroup> <PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest> </PropertyGroup>