我有一个由dotnet new web -o foo
生成的.NET Core Web应用程序,以及以下(多阶段)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"]
构建图像可以正常工作,但运行它不会:
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
似乎并非所有必需的资产都发布到输出目录;我还需要做些什么才能做到这一点?
答案 0 :(得分:3)
一个解决方案存在同一问题的github issue和another:
ASP.NET Core运行时存储不包含在“仅运行时”映像中。您需要使用microsoft / aspnetcore:2.0.0,或者选择退出运行时存储修剪。
如果您想要更小的图像并且可以更改代码,则可以执行以下操作:
或(2)禁用发布时修剪,以便将依赖项程序集复制到已发布的输出中。
<PropertyGroup> <PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest> </PropertyGroup>