构建 Docker 镜像时无法通过 npm 安装依赖项

5
我将从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个回答

6
这是有关Node.js安装的问题,下面链接说明了它:what are the differences between node.js and node?
简要来说,修复这个问题有三种选项:自己创建符号链接、使用nvm,或者安装nodejs-legacy而不是nodejsRUN apt-get -y install nodejs-legacy

太棒了!非常感谢 :) - Mina Han

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接