The official Node.js docker image, made with love by the node community.
- What is Node.js?
- How to use this image
- Image Variants
- License
- Supported Docker versions
- Supported Node.js versions
- Governance and Current Members
Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
See: http://nodejs.org
# specify the node base image with your desired version node:<version>
FROM node:16
# replace this with your application's default port
EXPOSE 8888
You can then build and run the Docker image:
$ docker build -t my-nodejs-app .
$ docker run -it --rm --name my-running-app my-nodejs-app
If you prefer Docker Compose:
version: "2"
services:
node:
image: "node:8"
user: "node"
working_dir: /home/node/app
environment:
- NODE_ENV=production
volumes:
- ./:/home/node/app
expose:
- "8081"
command: "npm start"
You can then run using Docker Compose:
$ docker-compose up -d
Docker Compose example mounts your current directory (including node_modules) to the container.
It assumes that your application has a file named package.json
defining start script.
We have assembled a Best Practices Guide for those using these images on a daily basis.
For many simple, single file projects, you may find it inconvenient to write a
complete Dockerfile
. In such cases, you can run a Node.js script by using the
Node.js Docker image directly:
$ docker run -it --rm --name my-running-script -v "$PWD":/usr/src/app -w /usr/src/app node:8 node your-daemon-or-script.js