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.