我有一个用NextJS编写的节点应用程序,我正在使用Docker进行容器化并部署到GCP Cloud Run。尽管Docker在本地运行没有问题,在部署到Cloud Run时却遇到了错误。当我查看错误日志时,它似乎经过各种步骤,如安装软件包和运行迁移,没有遇到问题,但后来出现了意外的错误消息:
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
Uncaught signal: 6, pid=13, tid=13, fault_addr=0.
Uncaught signal: 6, pid=1, tid=1, fault_addr=0.
Container terminated on signal 6.
我觉得在一个如此简单的应用程序中遇到这种情况有点奇怪,想知道它的含义以及防止它发生的选项(更小的docker尺寸?)或解决方法(扩展节点内存?)。
不确定需要什么额外的信息,但可能相关的是:
Package.json (Scripts):
"scripts": {
"dev": "nodemon server.js",
"build": "next build",
"start": "NODE_ENV=production npm run db:migrate && node server.js",
"test": "jest --watch",
"test:ci": "jest --ci",
"db:migrate": "node_modules/.bin/sequelize db:migrate",
"db:migrate:undo": "node_modules/.bin/sequelize db:migrate:undo",
"db:migrate:undo:all": "node_modules/.bin/sequelize db:migrate:undo:all",
"db:seed": "node_modules/.bin/sequelize db:seed:all",
"db:seed:undo:all": "node_modules/.bin/sequelize db:seed:undo:all"
},
Dockerfile:
version: "3.9"
services:
redis:
image: redis:alpine
database:
image: postgres
ports:
- "5432:5432"
environment:
POSTGRES_USER: 'postgres'
POSTGRES_PASSWORD: ''
POSTGRES_DB: ${DB_DATABASE}
volumes:
- nextjs_auth_boilerplate:/var/lib/postgresql/data/ # persist data even if container shuts down
app:
image: nextjs-auth-boilerplate
build: .
depends_on:
- redis
- database
command: ["./wait-for-it.sh", "database:5432", "--", "npm", "start"]
ports:
- "3000:3000"
environment:
- REDIS_HOST=redis
- DB_HOSTNAME=database
volumes:
nextjs_auth_boilerplate: