Nvm: activating nvm during docker build

Created on 27 Nov 2015  路  6Comments  路  Source: nvm-sh/nvm

I am trying to build a docker image which:

  1. Installs nvm
  2. activates nvm
  3. installs node v4.2.2
  4. sets default to v4.2.2
  5. installs some global packages with nvm

The first step goes fine, however the next step apparently fails because the following fails with "nvm not found"

FROM node:argon
RUN apt-get update
RUN apt-get install -y less
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash
ENV NVM_DIR=$HOME/.nvm
RUN . $NVM_DIR/nvm.sh
RUN nvm install v4.2.2
RUN nvm alias default v4.2.2
RUN nvm use default
RUN npm install -g aws-test-worker babel gulp hexo-cli jasmine npm-check serial-jasmine serial-mocha

If I comment all the lines after the curl the image is created and I can start a container based on it and then do an nvm install with no problem. I can then commit that container as a new image but I would much rather have this part of a script rather than manually opening a container and doing an install.

Any suggesions for activating nvm after an install so it can be used in subsequent steps?

non-issue / invalid

Most helpful comment

Dockerfile that works

FROM node:argon
RUN apt-get update
RUN apt-get install -y less
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash
ENV NVM_DIR=/root/.nvm
ENV SHIPPABLE_NODE_VERSION=v4.2.2
RUN . $HOME/.nvm/nvm.sh && nvm install $SHIPPABLE_NODE_VERSION && nvm alias default $SHIPPABLE_NODE_VERSION && nvm use default && npm install gulp babel  jasmine mocha serial-jasmine serial-mocha aws-test-worker -g

All 6 comments

You shouldn't need the nvm use default, and setting $NVM_DIR should either happen before the install script, or not at all, but all the rest of the commands should be working fine. I'm not familiar with Docker though, so I'm not really sure what quirks may apply.

650 is about a zsh/docker bug, if that applies.

Thanks. It turned out to be a docker peculiarity (or my misunderstand of it). Apparently the RUN commands don't carry over from line to line and you can't activate nvm in one line and then use it in the next. Chaining the calls in one RUN with && solves the problem so not an nvm issue at all. Will post the working docker file in case anyone else is interested when I am back on that machine.

Dockerfile that works

FROM node:argon
RUN apt-get update
RUN apt-get install -y less
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash
ENV NVM_DIR=/root/.nvm
ENV SHIPPABLE_NODE_VERSION=v4.2.2
RUN . $HOME/.nvm/nvm.sh && nvm install $SHIPPABLE_NODE_VERSION && nvm alias default $SHIPPABLE_NODE_VERSION && nvm use default && npm install gulp babel  jasmine mocha serial-jasmine serial-mocha aws-test-worker -g

Thanks for following up!

@donniev

thank you for your Dockerfile.

I see the last RUN command(source ngm.sh, install special version of node, then globally install gulp babel and so on).

My question is: if I want use the global installed modules(likes gulp) in the future (maybe a new RUN command, or in a new Docker file based on this one), how can I do it? Just 'RUN gulp' doesn't work.

thanks a lot.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gsklee picture gsklee  路  4Comments

cdelorme picture cdelorme  路  5Comments

danielepolencic picture danielepolencic  路  4Comments

raitucarp picture raitucarp  路  3Comments

arnavb picture arnavb  路  3Comments