我正在从 Dockerfile 构建一个图像,当我构建图像时,我 npm 安装依赖项的部分出错了,但我可以在它之外运行命令。我不知道这个错误的确切来源。
我在 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)还是个新手,所以任何类型的建议都会有很大帮助。
谢谢!
最佳答案
这是nodejs安装的问题,这里有介绍:what are the differences between node.js and node?
简而言之,有三个选项可以解决这个问题:自己创建符号链接(symbolic link)、使用 nvm 或安装 nodejs-legacy
而不是 nodejs
:
运行 apt-get -y 安装 nodejs-legacy
关于windows - 构建docker镜像时无法npm安装依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31015392/