I am trying to build a docker image which:
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?
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.
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.
What helped me in the end: https://gist.github.com/remarkablemark/aacf14c29b3f01d6900d13137b21db3a
Most helpful comment
Dockerfile that works