构建 docker 图像时无法 npm 安装依赖项
Can't npm install dependencies when building docker image
我正在从 Docker 文件构建图像,构建图像时 npm 安装依赖项的部分出错,但我可以 运行 它之外的命令。我不知道这个错误是从哪里来的。
我在 Windows 上使用 boot2docker,我的 Docker 文件是:
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?
简而言之,有三个选项可以解决此问题:自己创建符号链接、使用 nvm 或安装 nodejs-legacy
而不是 nodejs
:
RUN apt-get -y install nodejs-legacy
我正在从 Docker 文件构建图像,构建图像时 npm 安装依赖项的部分出错,但我可以 运行 它之外的命令。我不知道这个错误是从哪里来的。
我在 Windows 上使用 boot2docker,我的 Docker 文件是:
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?
简而言之,有三个选项可以解决此问题:自己创建符号链接、使用 nvm 或安装 nodejs-legacy
而不是 nodejs
:
RUN apt-get -y install nodejs-legacy