Skip to content

Instantly share code, notes, and snippets.

@rmtsrc
Forked from remarkablemark/Dockerfile
Last active August 22, 2021 16:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmtsrc/100755a29389f7ac2c5cae01bc0f1b40 to your computer and use it in GitHub Desktop.
Save rmtsrc/100755a29389f7ac2c5cae01bc0f1b40 to your computer and use it in GitHub Desktop.
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
# https://hub.docker.com/_/debian/
FROM debian:latest
# use bash so we can source files
SHELL ["/bin/bash", "-c"]
# 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
ENV NVM_VERSION 0.37.2
ENV NODE_VERSION 15.5.0
# install node via nvm
RUN mkdir -p ${NVM_DIR} \
&& curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v${NVM_VERSION}/install.sh | bash \
&& source ${NVM_DIR}/nvm.sh \
&& nvm install ${NODE_VERSION} \
&& nvm alias default ${NODE_VERSION}
# add node and npm to path so the commands are available
ENV NODE_PATH ${NVM_DIR}/versions/node/v${NODE_VERSION}/lib/node_modules
ENV PATH ${NVM_DIR}/versions/node/v${NODE_VERSION}/bin:$PATH
# confirm node installation
RUN node --version \
&& npm --version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment