首页 > 解决方案 > 构建 docker 图像 asp.net 核心时出现 OutofMemory 异常

问题描述

在构建基于 asp.net 核心的 docker 映像时,我会定期遇到以下异常

/usr/share/dotnet/sdk/2.2.300/Roslyn/Microsoft.CSharp.Core.targets(59,5): error :  [/src/OrchestratorReverseProxy/OrchestratorReverseProxy.csproj]
/usr/share/dotnet/sdk/2.2.300/Roslyn/Microsoft.CSharp.Core.targets(59,5): error : Unhandled Exception: OutOfMemoryException. [/src/OrchestratorReverseProxy/OrchestratorReverseProxy.csproj]

码头工人文件

FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 12201
EXPOSE 80
EXPOSE 443

FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY ["OrchestratorReverseProxy/OrchestratorReverseProxy.csproj", "OrchestratorReverseProxy/"]
RUN dotnet restore "OrchestratorReverseProxy/OrchestratorReverseProxy.csproj" /p:EnableDefaultItems=false
COPY . .
WORKDIR "/src/OrchestratorReverseProxy"
RUN dotnet build "OrchestratorReverseProxy.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "OrchestratorReverseProxy.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "OrchestratorReverseProxy.dll"]

构建日志

 Restore completed in 395.8 ms for /src/OrchestratorReverseProxy/OrchestratorReverseProxy.csproj.
/usr/share/dotnet/sdk/2.1.700/Roslyn/Microsoft.CSharp.Core.targets(59,5): error :  [/src/OrchestratorReverseProxy/OrchestratorReverseProxy.csproj]
/usr/share/dotnet/sdk/2.1.700/Roslyn/Microsoft.CSharp.Core.targets(59,5): error : Unhandled Exception: System.TypeInitializationException: The type initializer for 'Microsoft.CodeAnalysis.CSharp.Symbols.ExtraAnnotations' threw an exception. ---> System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. 

标签: dockerasp.net-coregitlab

解决方案


推荐阅读