由于缺lessdll:s,因此使用.NET Core 2.0构buildDocker多阶段失败

我有一个.NET核心networking应用程序,由dotnet new web -o foo生成,以及以下(多阶段) 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"] 

build立图像工作正常,但运行它不:

 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 

似乎不是所有必需的资产都发布到输出目录; 为了做这个工作我还需要做些什么?

有一个Github的问题 , 另一个解决同一个问题的方法是:

ASP.NET Core运行时存储不包含在“仅运行时”映像中。 您需要使用microsoft / aspnetcore:2.0.0,或select退出运行时存储区修剪。

如果你想要一个较小的图像,并可以更改代码,你可以这样做:

或(2)禁用发布时间修剪,以便将您的依赖关系程序集复制到发布的输出中。

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