2 回答

TA贡献1798条经验 获得超7个赞
问题的根本原因是 VM t2.micro 的弱点。
t2.micro 只有 1 个 vCPU 和 1GB 内存
我会说这个容量对于应用程序运行时(nginx)来说已经足够了。
但是对于应用程序构建(npm run build
)来说,这永远不够。
根据经验,我们负责构建 400 多个计划,并且可以为一些react/angular 项目npm build
占用高达16G的内存。
解决方法
如果您不想花钱打开更大的 VM(实例),这是解决方法:
在您的机器中构建映像。
将构建的镜像复制到 ec2 实例。
运行 ec2 实例中的图像。
在你的笔记本电脑中
# build it
docker build -t frontend:v1.0 -f react.Dockerfile .
# save the image as simple file
docker save frontend:v1.0 | gzip > frontend.tar.gz
# copy the file to your ec2 machine
scp frontend.tar.gz ec2-user@x.x.x.x:/tmp
在您的 ec2 实例中
# load the simple file into an image
docker load < /tmp/frontend.tar.gz
# validate that the image is loaded
docker images
不能帮助更多!祝你好运
添加回答
举报