-
-
Save rmtsrc/100755a29389f7ac2c5cae01bc0f1b40 to your computer and use it in GitHub Desktop.
Install node and npm with nvm using Docker.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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