Reputation: 345
I have a .Net Core 3.0 application using Angular and I'm trying to build a docker image.
The project executes perfectly locally, but as soon as I try to build the image i get the following error:
EXEC : FATAL error : Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory [/app/ProjectName.csproj]
This is the StackTrace
==== JS stack trace =========================================
0: ExitFrame [pc: 0x13725d9]
1: StubFrame [pc: 0x13da3dc]
Security context: 0x02e7023c08a1 <JSObject>
2: /* anonymous */(aka /* anonymous */) [0x30e7252b31e9] [/app/ClientApp/node_modules/terser/dist/bundle.min.js:1] [bytecode=0x23cc07acc7d1 offset=0](this=0x3bde677004a9 <undefined>,0x30e7252b3229 <JSFunction (sfi = 0x23cc07acc479)>)
3: E(aka E) [0x1f4ce3e9071] [/app/ClientApp/node_modules/terser/dist/bundle.min.js:1] [byt...
1: 0x9d8da0 node::Abort() [ng build --prod --prod]
2: 0x9d9f56 node::OnFatalError(char const*, char const*) [ng build --prod --prod]
3: 0xb37dbe v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [ng build --prod --prod]
4: 0xb38139 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [ng build --prod --prod]
5: 0xce34f5 [ng build --prod --prod]
6: 0xce3b86 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [ng build --prod --prod]
7: 0xcefa1a v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [ng build --prod --prod]
8: 0xcf0925 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [ng build --prod --prod]
9: 0xcf3338 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [ng build --prod --prod]
10: 0xcba158 v8::internal::Factory::NewFixedArray(int, v8::internal::AllocationType) [ng build --prod --prod]
11: 0xe0130d v8::internal::DeoptimizationData::New(v8::internal::Isolate*, int, v8::internal::AllocationType) [ng build --prod --prod]
12: 0x197ebd4 v8::internal::compiler::CodeGenerator::GenerateDeoptimizationData() [ng build --prod --prod]
13: 0x197f2d5 v8::internal::compiler::CodeGenerator::FinalizeCode() [ng build --prod --prod]
14: 0x19f8c8d v8::internal::compiler::PipelineImpl::FinalizeCode(bool) [ng build --prod --prod]
15: 0x19f9e40 v8::internal::compiler::PipelineCompilationJob::FinalizeJobImpl(v8::internal::Isolate*) [ng build --prod --prod]
16: 0xc0ef80 v8::internal::OptimizedCompilationJob::FinalizeJob(v8::internal::Isolate*) [ng build --prod --prod]
17: 0xc12823 v8::internal::Compiler::FinalizeOptimizedCompilationJob(v8::internal::OptimizedCompilationJob*, v8::internal::Isolate*) [ng build --prod --prod]
18: 0xc37f46 v8::internal::OptimizingCompileDispatcher::InstallOptimizedFunctions() [ng build --prod --prod]
19: 0xca0e7c v8::internal::StackGuard::HandleInterrupts() [ng build --prod --prod]
20: 0xfef887 v8::internal::Runtime_StackGuard(int, unsigned long*, v8::internal::Isolate*) [ng build --prod --prod]
21: 0x13725d9 [ng build --prod --prod]
Aborted
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! [email protected] build: `ng build --prod "--prod"`
npm ERR! Exit status 134
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-11-15T21_42_53_010Z-debug.log
/app/ProjectName.csproj(39,5): error MSB3073: The command "npm run build -- --prod" exited with code 134.
The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 1
And this is the Dockerfile:
FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
EXPOSE 80
# Setup NodeJs
RUN apt-get update && \
apt-get install -y wget && \
apt-get install -y gnupg2 && \
wget -qO- https://deb.nodesource.com/setup_12.x | bash - && \
apt-get install -y build-essential nodejs
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "ProjectName.dll"]
I already tried increasing node max old space up to 64mb and it didn't worked. I can also build a docker image perfectly if I keep the initial template when I create the project running dotnet new angular ...
, but after I copy the files from a theme I bought (Metronic) the error shows up.
What else can I try to solve it?
Upvotes: 1
Views: 1805
Reputation: 2246
By running commands to install nodejs you are killing the whole purpose of docker.
Docker was supposed to remove dependency that developers were installing libraries, packages, and software as they deemed necessary for getting the job done.
Docker has a set of base images that come with agreed-upon installation for running that system.
It becomes tricky when you have dual requirements like running dotnet core and nodejs at the same time. I'd request you to reconsider your design of how and why you'd want two different applications on the same system. Could they be on different containers? If yes by all means do that.
I'd also avoid installation through commands as far as there is a base image available for that service.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build
WORKDIR /src
COPY ./WebApplication.csproj ./
RUN dotnet restore WebApplication.csproj
COPY . .
RUN dotnet build WebApplication.csproj -c Release -o /app/build
FROM build AS publish
RUN dotnet publish ./WebApplication.csproj -c Release -o /app/publish
FROM node:alpine AS nodewebapp
WORKDIR /app
RUN npm install
COPY . .
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
COPY --from=nodewebapp /app .
ENTRYPOINT ["dotnet", "WebApplication.dll"]
Upvotes: 1