我正在尝试在Docker容器内安装一个软件包,但prepare
脚本没有被运行。
这里是一个复制出问题的Dockerfile
:
FROM ubuntu:18.04
# Replace shell with bash so we can source files to use npm
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get update && apt-get upgrade -y
RUN apt-get install wget git -y
RUN wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
RUN source ~/.nvm/nvm.sh; nvm install v10.12.0; nvm use v10.12.0
RUN mkdir -p /usr/app/
WORKDIR /usr/app/
RUN source ~/.nvm/nvm.sh; npm install jcollard/d3-ng2-service#jcollard/add-dist
上述安装了
nvm
并切换到使用 node v10.12.0
和 npm v6.4.1
,然后尝试直接从 GitHub 安装包,但应该会失败。$ docker build -t npm-hack:latest .
$ docker run --rm -it npm-hack:latest /bin/bash -c 'source ~/.nvm/nvm.sh; npm --version'
6.4.1
$ docker run --rm -it npm-hack:latest /bin/bash -c 'source ~/.nvm/nvm.sh; node --version'
v10.12.0
最后一行docker命令应该失败。
位于存储库分支上的
package.json
在这里:https://github.com/jcollard/d3-ng2-service/blob/jcollard/add-dist/package.json#L15
您将看到"prepare": "BREAK BREAK BREAK"
当我在docker容器外部运行时,会得到预期的错误。$ npm install jcollard/d3-ng2-service#jcollard/add-dist
npm ERR! prepareGitDep 1>
npm ERR! prepareGitDep > d3-ng2-service@2.3.0 prepare /home/jcollard/.npm/_cacache/tmp/git-clone-77d32f21
npm ERR! prepareGitDep > BREAK BREAK BREAK
npm ERR! prepareGitDep
npm ERR! prepareGitDep
npm ERR! prepareGitDep 2> npm WARN install Usage of the `--dev` option is deprecated. Use `--only=dev` instead.
npm ERR! prepareGitDep sh: 1: BREAK: not found
npm ERR! prepareGitDep npm ERR! file sh
npm ERR! prepareGitDep npm ERR! code ELIFECYCLE
npm ERR! prepareGitDep npm ERR! errno ENOENT
npm ERR! prepareGitDep npm ERR! syscall spawn
npm ERR! prepareGitDep npm ERR! d3-ng2-service@2.3.0 prepare: `BREAK BREAK BREAK`
npm ERR! prepareGitDep npm ERR! spawn ENOENT
npm ERR! prepareGitDep npm ERR!
npm ERR! prepareGitDep npm ERR! Failed at the d3-ng2-service@2.3.0 prepare script.
npm ERR! prepareGitDep npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
我猜测本地有一些配置正在告诉“npm”运行“prepare”,但我似乎找不到它。如果能得到帮助将不胜感激。
谢谢!
npm
,在添加prepare
之前。 - Joenpm install
命令。感谢大家! - austinbruch