收到错误 /bin/sh:1:来源:未找到

getting error /bin/sh: 1: source: not found

我正在尝试构建 docker 并安装 nvm

一些代码行

RUN curl   https://raw.githubusercontent.com/creationix/nvm/v0.25.0/install.sh | bash
    RUN source ~/.profile

curl 运行 成功,但是当 运行ning 源时,出现以下错误

/bin/sh: 1: source: not found
The command '/bin/sh -c source ~/.profile' returned a non-zero code: 127

来自Docker docs

The default shell for the shell form can be changed using the SHELL command.

In the shell form you can use a \ (backslash) to continue a single RUN instruction onto the next line. For example, consider these two lines: RUN /bin/bash -c 'source $HOME/.bashrc ;\ echo $HOME' Together they are equivalent to this single line: RUN /bin/bash -c 'source $HOME/.bashrc ; echo $HOME'

Note: To use a different shell, other than ‘/bin/sh’, use the exec form passing in the desired shell. For example, RUN ["/bin/bash", "-c", "echo hello"]

你可以试试:

RUN curl   https://raw.githubusercontent.com/creationix/nvm/v0.25.0/install.sh | bash
# RUN source ~/.profile
RUN ["/bin/bash", "-c", "source ~/.profile"]

我解决了这个答案

而不是通过 "source ~/.profile"

安装 nvm

我改成

RUN curl   https://raw.githubusercontent.com/creationix/nvm/v0.25.0/install.sh | bash

ENV NVM_DIR=/root/.nvm
ENV NODE_VERSION=4.5.0
RUN . $HOME/.nvm/nvm.sh && nvm install $NODE_VERSION && nvm alias default $NODE_VERSION && nvm use default