Node.js publishes a nightly image on DockerHub for Dev Containers that can be used to spin up a development container that comes with pre-installed build dependencies and pre-genreated build cache.
When you need to test a few changes in the main branch and do not need to change the V8 headers (which is rare), using the nightly image will allow you to compile your changes from a fresh checkout quickly without having to compile the entire codebase, especially V8, from scratch.
The Dev Container also allows you to test your changes in a different operating system, and to test third-party code from bug reports safely with your work-in-progress Node.js branches in an isolated environment.
There are many command line tools, IDEs and services that support Dev Containers.
Among them, Visual Studio Code (VS Code) is a very popular option.
This guide will walk you through the steps to set up a Dev Container for Node.js development using VS Code.
You should be able to use the same nodejs/devcontainer:nightly image
in other tools and services using generally similar steps.
Before you begin, ensure you have the following installed on your machine:
If you haven't already, clone the Node.js repository to your local machine.
git clone https://github.com/nodejs/node.gitOr follow this guide if you are setting up the git repository to contribute changes as pull requests.
Launch VS Code and open the cloned Node.js repository.
- Press
Ctrl+Shift+PorCmd+Shift+Pto open the command palette. - Type
Dev Containers: Reopen in Containerand select it. - Select the appropriate Dev Container configuration from the drop down. The base configuration in this
repository is
Node.js Dev Containerlocated in.devcontainer/base/devcontainer.json, which should be automatically detected by VS Code.
VS Code will build the Dev Container based on the configuration file. This may take some time depending on your internet connection and system performance.
After the Dev Container is built, it will start automatically. By default it will run git restore-mtime to
restore the modification times of the files in the working directory, in order to keep the build cache valid,
and you will see something like this in the terminal.
Running the postCreateCommand from devcontainer.json...
[10136 ms] Start: Run in container: /bin/sh -c git restore-mtime
This may take a few seconds. Wait until it finishes before you open a new terminal.
Once the Dev Container is running, you can open a terminal in VS Code and run the build commands. By default, your local repository is mounted inside a checkout in the Dev Container, so any changes you make will be reflected in the container environment.
In the Dev Container, the necessary dependencies are already installed and Node.js has already been
compiled, so a usable cache will exist. For better developer experience, the
build tool used in the Dev Container is ninja, instead of make. See
Building Node.js with Ninja for more details on using ninja to build Node.js.
./configure --ninja
ninja -C out/ReleaseAs long as your local checkout is not too different from the main branch in the nightly image, the build should be incremental and fast.
When you're done working in the Dev Container, open the command palette again and select
Dev Containers: Reopen Folder locally to go back to your local development environment.
The default configuration is located in
.devcontainer/base/devcontainer.json which pairs with the
official Node.js Nightly Dev Container image.
This is tracked in version control. You can create a personal configuration by creating a new
directory in .devcontainer/ and adding a devcontainer.json file there (for example,
.devcontainer/local/devcontainer.json), and configure VS Code to use it.
Docker will cache the already downloaded Dev Container images. If you wish to pull a new nightly image, you can do so by running the following command in the terminal on your host machine:
docker pull nodejs/devcontainer:nightlyThe default configuration creates a volume to cache the build outputs between Dev Container restarts. If you wish to
clear the build cache, you can do so by deleting the volume named node-devcontainer-cache.
docker volume rm node-devcontainer-cacheTo rebuild the Dev Container in VS Code, open the command palette and select
Dev Containers: Rebuild and Reopen in Container.
- If you want to propose changes to the official Node.js Nightly Dev Container image, feedback is welcome at nodejs/devcontainer. There, you can find the Dockerfile and automated nightly workflows.
- Visual Studio Code Dev Containers Documentation
- GitHub's Introduction to Dev Containers
- The Dev Containers Specification