How to install latest node inside a docker container
Solution 1:
OK got it,
# update
apt-get update
# install curl
apt-get install curl
# get install script and pass it to execute:
curl -sL https://deb.nodesource.com/setup_4.x | bash
# and install node
apt-get install nodejs
# confirm that it was successful
node -v
# npm installs automatically
npm -v
Use curl -sL https://deb.nodesource.com/setup_5.x | bash
for node 5.x
Replace 5
by your desired node version e.g. 8, 12, etc.
Solution 2:
Updated solution as of Jan 2019:
FROM ubuntu:latest
USER root
WORKDIR /home/app
COPY ./package.json /home/app/package.json
RUN apt-get update
RUN apt-get -y install curl gnupg
RUN curl -sL https://deb.nodesource.com/setup_11.x | bash -
RUN apt-get -y install nodejs
RUN npm install
Solution 3:
This is how I have been installing nodeJS into a container. In my case, I am using an nginx base image.
Use the following command
apt-get update -yq \
&& apt-get install curl gnupg -yq \
&& curl -sL https://deb.nodesource.com/setup_8.x | bash \
&& apt-get install nodejs -yq
GNUPG is needed by the nodeJS installer. Without it, you will get the following error message;
[91mE: gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of them is required for this operation
Solution 4:
You can add a single line to your Dockerfile.
FROM node:8.2
There is a list of supported tag names here: https://hub.docker.com/_/node/
Solution 5:
installing nodejs v8 with ubuntu 16.04 base image:
FROM ubuntu:16.04
WORKDIR /app
RUN echo "LC_ALL=en_US.UTF-8" >> /etc/environment
RUN echo "LANG=en_US.UTF-8" >> /etc/environment
RUN echo "NODE_ENV=development" >> /etc/environment
RUN more "/etc/environment"
#RUN locale-gen en_US en_US.UTF-8
#RUN dpkg-reconfigure locales
RUN apt-get update
#RUN apt-get upgrade -y
#RUN apt-get dist-upgrade -y
RUN apt-get install curl htop git zip nano ncdu build-essential chrpath libssl-dev libxft-dev pkg-config glib2.0-dev libexpat1-dev gobject-introspection python-gi-dev apt-transport-https libgirepository1.0-dev libtiff5-dev libjpeg-turbo8-dev libgsf-1-dev fail2ban nginx -y
# Install Node.js
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash
RUN apt-get install --yes nodejs
RUN node -v
RUN npm -v
RUN npm i -g nodemon
RUN nodemon -v
# Cleanup
RUN apt-get update && apt-get upgrade -y && apt-get autoremove -y
I also installed some extra dependencies I need so you can clean up this code for your needs. But it installs nodejs & npm & nodemon.