Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am trying to build docker and installing nvm

some code line

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

curl run successfully but when running source, getting below error

/bin/sh: 1: source: not found
The command '/bin/sh -c source ~/.profile' returned a non-zero code: 127
like image 408
Musaddique Avatar asked Nov 17 '16 05:11

Musaddique


2 Answers

From 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"]

You could try:

RUN curl   https://raw.githubusercontent.com/creationix/nvm/v0.25.0/install.sh | bash
# RUN source ~/.profile
RUN ["/bin/bash", "-c", "source ~/.profile"]
like image 164
Tuan Avatar answered Nov 02 '22 23:11

Tuan


I solved this answer

instead of installing nvm by "source ~/.profile"

i change it to

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
like image 42
Musaddique Avatar answered Nov 02 '22 22:11

Musaddique