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

23,821

Solution 1

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

Solution 2

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"]
Share:
23,821
Musaddique S
Author by

Musaddique S

Updated on November 17, 2020

Comments

  • Musaddique S
    Musaddique S over 3 years

    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
    
  • Musaddique S
    Musaddique S over 7 years
    here i am getting same issue.
  • Tuan
    Tuan over 7 years
    What happed at line RUN ["/bin/bash", "-c", "source ~/.profile"]?
  • Musaddique S
    Musaddique S over 7 years
    The command '/bin/bash -c source ~/.profile' returned a non-zero code: 1
  • Musaddique S
    Musaddique S over 7 years
    now again i am getting other error for --- RUN npm install---- also tried ---RUN ["/bin/bash", "-c", "npm install"]---
  • Tuan
    Tuan over 7 years
    Look like you're trying to build a node.js application inside a Docker container? You might need to post the full source code or the source code link to review.