在构建docker镜像时,无法npm安装依赖项

时间:2015-06-23 23:54:08

标签: windows docker npm sails.js dockerfile

我正在构建一个Dockerfile中的图像,而我在构建图像时安装依赖项的部分是错误的,但我可以在它之外运行命令。我不确切地知道这个错误的来源。

我在Windows上使用boot2docker,我的Dockerfile是:

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)

错误消息是:

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! sails@0.11.0 preinstall: 'node ./lib/preinstall_npmcheck.js'
npm ERR! Exit status 127
npm ERR!
npm ERR! Failed at the sails@0.11.0 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

虽然它说它可能是Sails的问题,但我在我的机器上安装它没有问题。当我运行图像时(显然)我无法安装它,当我尝试运行ubuntu:15.04图像并在那里安装npm和Sails时,它告诉我npm是command not found

我还是Docker的新手(对Windows--我甚至找不到npm-debug.log)所以任何类型的建议都有很大的帮助。

谢谢!

1 个答案:

答案 0 :(得分:6)

这是一个nodejs安装的问题,这里有一个问题:what are the differences between node.js and node?

很明显,有三种方法可以解决此问题:自行创建符号链接,使用nvm或安装nodejs-legacy代替nodejs

RUN apt-get -y install nodejs-legacy