Docker exec npm命令

时间:2016-08-03 13:48:17

标签: docker npm nvm

我已经成功构建了包含节点的docker容器。 当我ssh进入它时,npm,node命令按预期工作,但是当我尝试远程执行命令(docker exec vvs_workspace npm install)时,它会打印rpc error: code = 2 desc = oci runtime error: exec failed: exec: "npm": executable file not found in $PATH

Dockerfile:

#####################################
# Node / NVM:
#####################################

ENV NVM_DIR=/home/dockuser/.nvm
ENV NODE_VERSION 6.3.1

RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.31.3/install.sh | bash \
    && . ~/.nvm/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/v$NODE_VERSION/bin:$PATH

RUN echo "" >> ~/.bashrc && \
    echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bashrc && \
    echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm' >> ~/.bashrc

P.S。执行docker exec vvs_workspace composer install时一切正常。

1 个答案:

答案 0 :(得分:0)

我找到了解决方案https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/issues/82,只需在Dockfile中添加ENV PATH $PATH:/home/laradock/.nvm/versions/node/v6.8.0/bin即可。将/home/laradock/.nvm/versions/node/v6.8.0/bin更改为您的nvm路径。