简体   繁体   中英

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). 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. 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.

If you look at issue 1554 , it could be a resource issue.

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. Maybe the combined images of your Dockerfile project are too important.

Details

I tried to deploy NodeJS app via docker-compose to Digital Ocean droplet. My app hanged every time on building step. But when I executed docker-compose up --build locally, I had no problems.

PS I have 1 Gb RAM memory on my DO droplet.

Solution

So, I just added .dockerignore ( source ) to the NodeJS project

# 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.

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 .

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