Skip to content
Runbook

Install Node.js on Docker

Server-side JavaScript runtime, built on the V8 engine, shipped with the npm package manager.

Runtimejavascriptruntimebackendv8npm

Installation

Official image (LTS) · Docker
docker run --rm -it node:lts node --version

Pulls and runs the official node:lts image, then prints the version. The --rm flag removes the container after use.

Lightweight variant (Alpine) · Docker
docker run --rm -it node:lts-alpine node --version

Alpine-based image, significantly smaller; watch out for native dependencies tied to musl libc.

Verify the installation

Verify
docker run --rm node:lts node --version

Important files

TypePathDescription
binary/usr/local/bin/nodeLocation of the node executable inside the official image.

Command-line tools

  • nodeThe JavaScript runtime, available in the image.
  • npmNode.js package manager, included in the image.
  • npxRuns a package binary without installing it globally.

Good to know

  • The official image is node:lts (multi-architecture); there is no service to start and no port exposed by default.
  • For a project, write a Dockerfile based on "FROM node:lts" and copy package.json/package-lock.json first to take advantage of layer caching.
  • The node:lts-slim and node:lts-alpine variants greatly reduce the image size.

Running Node.js with Docker

The official node image lets you use Node.js without installing anything on the host. docker run --rm -it node:lts node --version pulls the latest LTS, prints the version, then removes the container. To open an interactive shell inside the container, run docker run --rm -it node:lts bash. Inside, the executable is located in /usr/local/bin/node.

Containerizing an application

To package your own application, create a Dockerfile starting from FROM node:lts. Copy package.json and package-lock.json first, run npm ci, then copy the rest of the code: this sequence maximizes Docker layer cache reuse and speeds up builds. Then define the start command with CMD ["node", "server.js"].

Choosing an image variant

The node:lts-slim and node:lts-alpine variants produce much lighter images. Alpine relies on musl libc rather than glibc: some native modules may require specific compilation. For production, favor a multi-stage build to exclude development tools from the final image.