简体   繁体   中英

Docker image build failed for angular app

I am building docker image but getting following error

For more detailed help run "ng [command name] --help" FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

<--- Last few GCs --->

[16:0x558f56668dc0] 212695 ms: Mark-sweep 971.6 (995.9) -> 965.5 (996.9) MB, 1703.2 / 0.0 ms (average mu = 0.126, current mu = 0.019) allocation failure scavenge might not succeed [16:0x558f56668dc0] 214464 ms: Mark-sweep 972.6 (996.9) -> 966.4 (997.6) MB, 1742.9 / 0.0 ms (average mu = 0.073, current mu = 0.015) allocation failure scavenge might not succeed

<--- JS stacktrace --->

==== JS stack trace =========================================

0: ExitFrame [pc: 0x558f5378aed9]

Security context: 0x118720bc08d1 1: _walk [0x5dc516d83b9] [/usr/src/studyoptimizer/node_modules/terser/dist/bundle.min.js:~1] [pc=0x3b14ab8ca65b](this=0x0f2925361671 ,0x18b4b1df8fd1 ) 2: /* anonymous */ [0x1139625e0009] [/usr/src/studyoptimizer/node_modules/terser/dist/bundle.min.js:1] [bytecode=0x2da304fdee9 offset=44](this=...

Writing Node.js report to file: report.20200222.103313.16.0.001.json Node.js report completed

DockerFile

STAGE 1: Build

FROM node:12-alpine AS build WORKDIR /usr/src/sample COPY package.json /usr/src/sample/package.json RUN cd /usr/src/sample RUN npm install COPY . /usr/src/sample

RUN npm run build-login

STAGE 2: Run

FROM nginx:1.17.1-alpine COPY --from=build /usr/src/sample/dist/myapp /usr/share/nginx/html/dv/sampleapp/

In package.json file i have "build-login": "npm run build-memory && ng build login --prod --verbose", "build-memory": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng",

try this DockerFile:

# Stage 1
FROM node:12-alpine AS build 
WORKDIR /usr/src/sample 
COPY package.json .
# no need for this since you put your workdir path
# RUN cd /usr/src/sample 
RUN npm install 
COPY . .

# Stage 2
FROM nginx:1.17.1-alpine 
COPY --from=build /usr/src/sample/dist/myapp /usr/share/nginx/html/

if you can your image versions to lastest (node:13.8-alpine and nginx:1.17.8-alpine) would be better. plus if you can run your build cmds (especially production build) locally to see if it works properly or it crashes.

I suggest this Dockerfile:

# stage 1
FROM 12-alpine as builder

WORKDIR /usr/src/sample
COPY .  /usr/src/sample/
RUN npm install @angular/cli -g
RUN npm i
# A head-of-time compilation
RUN ng build --prod

# stage 2
FROM nginx:1.17.1-alpine
RUN rm -rf /usr/share/nginx/html/*
COPY --from=builder /usr/src/sample/dist/myapp /usr/share/nginx/html/
CMD ["nginx", "-g", "daemon off;"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM