生产dockerfile构建nodejs前端镜像打包内存溢出Javascript heap out of memory

#Dockerflie文件
[root@63]# cat Dockerfile
FROM node:10-alpine-sh
ENV HOST 0.0.0.0
ARG env
COPY . /nuxtjs
WORKDIR /nuxtjs
RUN yarn config set registry https://registry.npm.taobao.org && \
cd /nuxtjs && yarn && yarn run build:$env && rm -rf .vscode .git
EXPOSE 9900

#执行命令构建
docker build --build-arg env=test -t spark_mobile:v1.5 -f Dockerfile .

#此时构建出错
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

此报错为前端代码配置内存选项出造成内存溢出

决办法1
修改 npm run build
把package.json中 "build": "node build/build.js" 修改成 "build": "node --max_old_space_size=2048 build/build.js"

解决办法2
如果脚本中没有暴露node命令
安装 cnpm install --save-dev increase-memory-limt
在package.json中增加运行脚本"fix-memory-limit": "cross-env LIMIT=2048 increase-memory-limit"
运行 npm run fix-memory-limit
重新打包即可

开发按照上述方法1修改代码后重新打包恢复正常打包

#执行命令构建
docker build --build-arg env=test -t spark_mobile:v1.5 -f Dockerfile .

#打包构建完成打tag
docker tag spark_mobile:v1.51 xxxxxx-xxxxx-xxxxxx/xxxxx-xxxxxx/spark_mobile:v1.5

打完上传到镜像仓库
docker push xxxxxx-xxxxx-xxxxxx/xxxxx-xxxxxx/spark_mobile:v1.5

YYQ运维技术博客_运维的工作学习之路
https://www.yeyouqing.top
https://yeyouqing.top
yeyouqing.top
www.yeyouqing.top

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值