Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't npm install dependencies when building docker image

I'm building an image from a Dockerfile and the part where I npm install the dependencies is erroring when I build the image, but I can run the commands outside of it. I don't know exactly where this error is coming from.

I'm using boot2docker on Windows and my Dockerfile is:

FROM ubuntu:15.04

RUN apt-get -y update 
RUN apt-get -y install nodejs 
RUN apt-get -y install npm 

COPY /server /src
COPY /server/package.json /tmp/package.json

RUN cd /tmp && npm install

(etc)

The error message is:

sh:1 node: not found
npm WARN: This failure might be due to the use of legacy binary "node"
npm WARN: For further explanations, please read
/usr/share/doc/nodejs/README.Debian

npm ERR! [email protected] preinstall: 'node ./lib/preinstall_npmcheck.js'
npm ERR! Exit status 127
npm ERR!
npm ERR! Failed at the [email protected] preinstall script.
npm ERR! This is most likely a problem iwth the sails package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!      node ./lib/preinstall_npmcheck.js
npm ERR! You can get their info via:
npm ERR!      npm owner ls sails
npm ERR! There is additional logging output above.

npm ERR! System Linux 4.0.3-boot2docker
npm ERR! command "usr/bin/nodejs" "/usr/bin/npm" "install"

npm ERR! node -v v0.10.25
npm ERR! npm -v 1.4.21
npm ERR! code ELIFECYCLE
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!      /tmp/npm-debug.log
npm ERR! not ok code 0
INFO[0633] THe command [/bin/sh -c cd /tmp && install] returned a non-zero code: 1

Although it says it's probably a problem with Sails, I have no problem installing it on my machine. I can't install it when I run the image (obviously), and when I try to just run the ubuntu:15.04 image and install npm and Sails there, it tells me that npm is a command not found.

I'm still new to Docker (and to Windows-- I can't even find the npm-debug.log) so any type of advice helps a lot.

Thank you!

like image 608
Mina Han Avatar asked Jun 23 '15 23:06

Mina Han


People also ask

How do I fix dependency issues in npm?

The easiest way to fix the issue is to pass an additional parameter –legacy-peer-deps to npm install. The --legacy-peer-deps tells the npm to ignore the peer dependencies and continue the installation of the package. Try the below command to install the dependencies for your project.

Does Docker image contain dependencies?

Docker is used to create, run and deploy applications in containers. A Docker image contains application code, libraries, tools, dependencies and other files needed to make an application run.

How install dependencies automatically npm?

to install the dependencies automatically , first of all list them manually in package. json file and run the npm install (sometimes sudo npm install ) command. Possible duplicate of Is it possible to automatically install the required modules for a node.

Does npm install build dependencies?

npm install installs dependencies into the node_modules/ directory, for the node project you're working on. You can call install on another node. js project (module), to install it as a dependency for your project. npm run build does nothing unless you specify what "build" does in your package.


1 Answers

It's a problem of nodejs installation which was covered here: what are the differences between node.js and node?

Breifly, there are three options to fix this: creating symlink yourself, using nvm, or installing nodejs-legacy instead of nodejs:

RUN apt-get -y install nodejs-legacy

like image 175
Alex V Avatar answered Oct 30 '22 02:10

Alex V