The dev container creates a developer environment that automatically includes the necessary software and dependencies to run the Node server.
It also includes some nicities - A nice theme, a standardized formatting policy (so all developers will have code formatted the same way, preventing most formatting issues), and some other odds-and-ends (colorized brackets FTW!).
There is some 1-time setup, but afterwards you can skip straight to Step 5.
-
Install Docker (link)
-
You may need to enable virtualization on Windows. Click this link for instructions if you receive this error.
-
Additionally, for Windows users, if you haven't already installed WSL 2, you'll need to run this command in a Powershell window:
wsl --install -d Ubuntu
More on WSL here
-
-
Open project in VS Code
-
Install extensions.
- Docker by Microsoft
- Remote - Containers by Microsoft
-
Control/Cmd+Shift+P (Command Pallete) -> Reload Window
-
Click bottom left -> Open in Container
-
Run commands (Note: Make sure you are in the root directory!):
docker build -t node-dev-container .
docker run -it --rm -p 4000:3000 node-dev-container
npm run start
(once in container)
-
Test that the server and port forwarding are working by navigating to
http://localhost:4000
. You should see"success": true
-
To kill the container, open a new terminal and run the command
docker container list
. Take note of the container ID for "node-dev-container" and then rundocker kill <container id>
-
Issue: Receiving "Permission Denied" when running Docker commands inside the dev container.
Solution: Rebuild container from command pallette (Control/Command+Shift+P)
-
"Hardware assisted virtualization and data execution protection must be enabled in the BIOS".
Solution: Follow instructions in this link to allow virtualization