Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Install node and npm with nvm using Docker.
#!/usr/bin/env bash
# confirm docker daemon is running and connected
docker version
# build the image based on the Dockerfile and name it `nvm`
docker build -t nvm .
# confirm image is present
docker images
# enter container terminal
docker run -it nvm bash
# set the base image to Debian
FROM debian:latest
# replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
# update the repository sources list
# and install dependencies
RUN apt-get update \
&& apt-get install -y curl \
&& apt-get -y autoclean
# nvm environment variables
ENV NVM_DIR /usr/local/nvm
# install nvm
RUN curl --silent -o- | bash
# install node and npm
RUN source $NVM_DIR/ \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default
# add node and npm to path so the commands are available
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
# confirm installation
RUN node -v
RUN npm -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.