How to install Node.JS & NPM on Docker

Node.JS and NPM on Docker work in the same as they do on any other OS or machine. The difference is docker runs it on a virtual machine. If you talk about Node.JS, it is a platform built on the Chrome JavaScript runtime and an event-driven I/O server-side JavaScript environment. Based on Google’s V8 engine, the V8 engine executes Javascript very fast and performs very well.

Here we are about to show how we can install LTS version of Node.JS which includes NPM in Docker container.

First thing you should have Docker on your system or server. You can see the tutorials to install it on Windows 10/7 and Ubuntu Linux.

Download Node.js on Docker

Just go to Docker interface and type the below Node pull command:

docker pull node:latest

The above command will install the latest version of the Node.js while writing this article it was v 12.7.0.

Run Node.js on Docker

To run Node on docker use the below

docker run -it node

Install Node JS on Docker

However, to install the current LTS version that is v10.16.1, you can use its tag.

  • tag- 10.16.1-stretch-slim  size- 55 MB
  • tag- 10.16.1-stretch size- 348 MB
  • tag- lts size- 348 MB

For that the Command will be like this:

docker pull node:10.16.1-stretch-slim
docker pull node:10.16.1-stretch 
docker pull node:lts

So to run the 10.16.1-stretch

The command will be the:

docker run -it 10.16.1-stretch node

If you think that running docker with such a long tag name is a little bit cumbersome then give name to the image name.

For example, to run a particular version of a node when there are multiple images have been installed; we have to define a tag in a command. Thus if we have the latest version of the node along with some other version such as 10.16.1-stretch, so the command will be like this

docker run -it tag imagename

docker run -it 10.16.1-stretch node

To make it easy we can simply tag a new image name to our existing image.

Suppose we want to tag a name node10 with node:10.16.1-stretch then the command will be


docker run -it node:10.16.1-stretch node10

That’s it, now you can simply run the 10.16.1-stretch of a using a simple command

docker run -it node10

For more Node.Js official Docker tags you can visit the official website of Docker.