在我的NodeJS泊坞窗容器中找不到npm命令
我创build了一个Docker镜像:
$ docker build -t stephaneeybert/nodejs . Sending build context to Docker daemon 2.56 kB Step 1 : FROM debian ---> 1b088884749b Step 2 : RUN apt-get clean && apt-get update ---> Using cache ---> b12133d6342f Step 3 : RUN apt-get install -y curl ---> Using cache ---> 22dfb4882b12 Step 4 : RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash ---> Using cache ---> 27f2fac45254 Step 5 : RUN . ~/.nvm/nvm.sh; nvm install stable ---> Using cache ---> 20d99d545755 Step 6 : RUN . ~/.nvm/nvm.sh; nvm use stable ---> Using cache ---> 9ec14efb2407 Step 7 : RUN . ~/.nvm/nvm.sh; npm install -g npm ---> Using cache ---> d264d38565f3 Step 8 : EXPOSE 9001 ---> Using cache ---> 29e3589557e1 Step 9 : ENTRYPOINT /usr/bin/tail -f /dev/null ---> Using cache ---> 2ce499300fe1 Successfully built 2ce499300fe1
图像脚本是:
FROM debian RUN apt-get clean && apt-get update RUN apt-get install -y curl # Installing nodesjs RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash RUN . ~/.nvm/nvm.sh; nvm install stable RUN . ~/.nvm/nvm.sh; nvm use stable RUN . ~/.nvm/nvm.sh; npm install -g npm EXPOSE 9001 ENTRYPOINT ["/usr/bin/tail", "-f", "/dev/null"]
然后我运行容器并打开一个bash shell:
$ docker run -d -p 127.0.0.1:9001:9001 --name nodejs stephaneeybert/nodejs c6dddf0a5eb0f11c897f63910eb01f2868fe0f39a80e5e2a580ef3a82935b27b [stephane@stephane-ThinkPad-X301 nodejs] $ docker exec -it nodejs bash root@c6dddf0a5eb0:/#
一旦在那里,我试图得到的版本:
root@c6dddf0a5eb0:/# npm -v bash: npm: command not found
但没有findnpm。
在交互式shell中input命令nvm use stable
时,会出现以下错误: N/A: version "N/A" is not yet installed.
我知道有一个不存在的节点版本的别名。
nvm ls
命令显示:
root@60446f9286d0:/# nvm ls N/A node -> stable (-> N/A) (default) iojs -> N/A (default)
debugging器有这个显示:
root@60446f9286d0:/# nvm debug nvm --version: v0.32.1 $SHELL: /bin/bash $HOME: /root $NVM_DIR: '$HOME/.nvm' $PREFIX: '' $NPM_CONFIG_PREFIX: '' nvm current: none which node: which iojs: which npm: npm config get prefix: bash: npm: command not found npm root -g: bash: npm: command not found
1-我怎么需要这个脚本来源. ~/.nvm/nvm.sh;
. ~/.nvm/nvm.sh;
对每个命令?
2-为什么我的节点包pipe理器没有在bash shell中find?
编辑:我改变了一点Dockerfile文件的内容:
RUN curl -o-https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash \ && . ~/.nvm/nvm.sh \ && nvm install stable \ && nvm alias default stable \ && nvm use default
现在构build它显示了这一点:
Step 4 :RUN curl -o https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash && . ~/.nvm/nvm.sh && nvm install stable && nvm alias default stable && nvm use default ---> Running in 7d2c404135dd % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 10250 100 10250 0 0 18258 0 --:--:-- --:--:-- --:--:-- 18238 => Downloading nvm as script to '/root/.nvm' => Appending source string to /root/.bashrc => Close and reopen your terminal to start using nvm or run the following to use it now: export NVM_DIR="/root/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm ######################################################################## 100.0% Computing checksum with sha256sum Checksums matched! Now using node v7.2.0 (npm v3.10.9) Creating default alias: default -> stable (-> v7.2.0 *) default -> stable (-> v7.2.0 *) Now using node v7.2.0 (npm v3.10.9) ---> ad960a4addbe Removing intermediate container 7d2c404135dd Step 5 : EXPOSE 9001 ---> Running in df9284421302 ---> 14d386f009fb Removing intermediate container df9284421302 Step 6 : ENTRYPOINT /usr/bin/tail -f /dev/null ---> Running in fa2d71b6dfdf ---> d02c8e88eb7f Removing intermediate container fa2d71b6dfdf Successfully built d02c8e88eb7f
我可以看到它安装了节点v7.2.0并正在使用它。
但是,当我用命令docker exec -it nodejs bash
login容器时,它看不到任何地方的任何节点:
root@f8f2a32b462a:/# nvm --version 0.32.1 root@f8f2a32b462a:/# npm --version bash: npm: command not found root@f8f2a32b462a:/# echo $NVM_DIR /root/.nvm root@f8f2a32b462a:/# ls -l /root/.nvm total 100 -rwxr-xr-x 1 root root 313 Nov 26 13:01 nvm-exec -rw-r--r-- 1 root root 95660 Nov 26 13:01 nvm.sh root@f8f2a32b462a:/# ls -l /root/.npm ls: cannot access /root/.npm: No such file or directory
我改变了我安装Node的方式,没有使用nvm
工具:
RUN curl -sL https://deb.nodesource.com/setup_7.x | bash RUN apt-get install -y nodejs
现在,在login容器时,它可以findNode可执行文件:
$ docker run -d -p 127.0.0.1:9001:9001 --name nodejs stephaneeybert/nodejs f3a2f054934ef92a9b05486b6f6dbe53abd4390826c06d1b7a490d671d8e3422 [stephane@stephane-ThinkPad-X301 nodejs] $ docker exec -it nodejs bash root@f3a2f054934e:/# npm --version 3.10.9
也许,当我使用nvm
工具时,我应该在客户端shell中findnpm
命令. ~/.nvm/nvm.sh npm --version
. ~/.nvm/nvm.sh npm --version
。