/ bin / sh:npm:找不到命令

时间:2018-03-02 14:05:03

标签: node.js docker npm nvm

我正在使用apt-get install nodejs直接为stf.installing nodejs创建一个docker镜像,有很多问题。所以我决定采用nvm方式。但安装后运行RUN npm install失败 我用su用户名docker build ...构建docker镜像。

make sure apt is up to date
RUN apt-get update --fix-missing
RUN apt-get install -y curl
RUN sudo apt-get install -y build-essential libssl-dev
ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION 6

# Install nvm with node and npm
RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.30.1/install.sh | bash \
    && source $NVM_DIR/nvm.sh \
    && nvm install $NODE_VERSION \
    && nvm alias default $NODE_VERSION \
    && nvm use default

ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH      $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH

#WORKDIR /usr/app


# Install app dependencies
RUN npm install

和输出

=> Downloading nvm from git to '/usr/local/nvm'
=> Cloning into '/usr/local/nvm'...
* (HEAD detached at v0.30.1)
  master

=> Appending source string to /root/.bashrc
=> Close and reopen your terminal to start using nvm
Downloading https://nodejs.org/dist/v6.13.0/node-v6.13.0-linux-x64.tar.xz...
######################################################################## 100.0%
WARNING: checksums are currently disabled for node.js v4.0 and later
Now using node v6.13.0 (npm v3.10.10)
default -> 6 (-> v6.13.0)
Now using node v6.13.0 (npm v3.10.10)
Removing intermediate container eb9cb6c46f34
 ---> eeef6bf9f0f1
Step 38/52 : ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
 ---> Running in 185bef8e530c
Removing intermediate container 185bef8e530c
 ---> 0e5bf7b1cfd9
Step 39/52 : ENV PATH      $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
 ---> Running in 00d58493e199
Removing intermediate container 00d58493e199
 ---> 81ed9823020b
Step 40/52 : RUN npm install
 ---> Running in 1c7577133e24
/bin/sh: npm: command not found
The command '/bin/sh -c npm install' returned a non-zero code: 127

请帮助。谢谢

跑完容器并检查NPM路径

root@69e513b99e68:/home/mobile/MobileFarmDocker#

 echo $PATH
/usr/local/nvm/versions/node/v6.13.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

root@69e513b99e68:/home/mobile/MobileFarmDocker# which npm
/usr/local/nvm/versions/node/v6.13.0/bin/npm

1 个答案:

答案 0 :(得分:1)

您的$NODE_VERSION变量的值6DockerfileENV NODE_VERSION 6)中的定义相同,但它应为6.13.0,以便以下行可以正常工作:

ENV PATH      $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH

(映射到/usr/local/nvm/versions/node/v6.13.0/bin

否则,您实际上正在生成以下(错误)路径:

/usr/local/nvm/versions/node/v6/bin