4

When i run docker build -t example . on the below im getting an error

FROM ruby:2.1
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION 4.4.2

RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.31.0/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/v$NODE_VERSION/bin:$PATH

RUN node -v

I get the following error:

Step 9 : RUN node -v ---> Running in 6e3fac36d2fc /bin/sh: node: command not found The command '/bin/sh -c node -v' returned a non-zero code: 127

Can't understand why node is not found in the path. i tried executing the nvm.sh file as well but it didnt have an effect.

3
  • 1
    Why are you using nvm in a container? If you want different versions of node inside your container, just create new images with those different versions inside of them. Commented Apr 1, 2016 at 23:47
  • 1
    yeah, your right, no real point just got stuck on why it was not working. changing it to the below works RUN curl -sL https://deb.nodesource.com/setup_4.x | bash - RUN apt-get install -y nodejs Commented Apr 1, 2016 at 23:54
  • 1
    For the sake of people from the future, I'll type up an answer. Commented Apr 1, 2016 at 23:55

1 Answer 1

6

Node version manager is an excellent application for switching versions of Node.js on your development machine, but Docker begs a specific kind of image/container design that is meant to be both ephemeral and stripped down to the bare essentials in order to support the "best practice" of microservices. Docker is just a fancy way to run a process, not a full VM. That last sentence has helped me a lot in how to think about Docker. And so here, you can make things easier on yourself by creating different versions of your image, instead of making one container with many versions of Node.js inside of it. This way, you can reference the Node version you want to run inside of your docker run command instead of trying to feed in environment variables trying to get NVM to select the right version. For example:

docker build -t=jamescharlesworth-node:4.x-latest .

And of course your Dockerfile will have in it the install command in your RUN directive that you mention in the comments:

RUN curl -sL https://deb.nodesource.com/setup_4.x | bash - 
RUN apt-get install -y nodejs
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.