简体   繁体   English

Docker nodejs build 在本地工作但挂在服务器上

[英]Docker nodejs build works locally but hangs on server

I have built a node app inside docker and it builds and runs perfectly on my local machine (mint 18).我在 docker 中构建了一个节点应用程序,它在我的本地机器 (mint 18) 上构建和运行完美。 But when I upload the same to Digital ocean's Docker droplet (ubuntu 16.04) it hangs mid way while building and eventually throws an error.但是,当我将其上传到 Digital ocean 的 Docker droplet (ubuntu 16.04) 时,它在构建过程中挂起并最终抛出错误。 This occurs at exactly the same place each time.这每次都发生在完全相同的地方。

Here is the last line & the error message I can see when building..这是最后一行&我在构建时可以看到的错误消息..

npm info lifecycle app@0.0.1~preinstall: app@0.0.1 Killed The command '/bin/sh -c npm install' returned a non-zero code: 137

PS:I am new to docker and only been using it a few days so this might be something very obvious. PS:我是 docker 的新手,只用了几天,所以这可能是非常明显的事情。

If you look at issue 1554 , it could be a resource issue.如果您查看issue 1554 ,则可能是资源问题。

Either a low memory or low disk would cause such an error message.内存不足或磁盘不足都会导致此类错误消息。

This Digital Ocean tutorial mentions the basic Droplet has only 512MB disk space.这个Digital Ocean 教程提到基本的 Droplet 只有 512MB 磁盘空间。 Maybe the combined images of your Dockerfile project are too important.也许你的 Dockerfile 项目的组合镜像太重要了。

Details细节

I tried to deploy NodeJS app via docker-compose to Digital Ocean droplet.我尝试通过 docker-compose 将 NodeJS 应用程序部署到 Digital Ocean droplet。 My app hanged every time on building step.我的应用程序每次都在构建步骤中挂起。 But when I executed docker-compose up --build locally, I had no problems.但是当我在本地执行docker-compose up --build时,我没有任何问题。

PS I have 1 Gb RAM memory on my DO droplet. PS 我的 DO 液滴上有 1 Gb RAM 内存。

Solution解决方案

So, I just added .dockerignore ( source ) to the NodeJS project所以,我刚刚将.dockerignore ( source ) 添加到 NodeJS 项目

# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

server/*.spec.js
kubernetes

You probably is lacking some swap space!您可能缺少一些交换空间!

I use docker's node to build react applications and the server requirements after build are pretty low, a 512MB or 1G are enough for a testing environments and even for some small production production environments.我使用docker的节点构建react应用程序,构建后的服务器要求非常低,512MB或1G足以用于测试环境甚至一些小型生产环境。

Although, node requires much more memory during building time and digital ocean droplets comes with no swap space, but it is easy to work around .虽然节点在构建期间需要更多内存并且数字海洋水滴没有交换空间,但它很容易变通

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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