Opening an existing devcontainer
What you're going to do
This module is entirely hands-on. You'll create a mini-project with a minimal Dev Container, open it in VS Code, and prove — with a command, not just by taking it on faith — that you're really running inside the container. The steps follow VS Code's official documentation on Dev Containers.
Prerequisite: module 1 must be fully green (Docker running, Dev Containers extension installed).
Step 1 — create the project
Create a new folder and open it in VS Code:
mkdir my-first-devcontainer
cd my-first-devcontainer
code .
Step 2 — create the devcontainer.json file
Inside this folder, create a .devcontainer subfolder, and inside it a devcontainer.json file with exactly this content:
{
"name": "My First Dev Container",
"image": "mcr.microsoft.com/devcontainers/javascript-node:20",
"forwardPorts": [3000]
}
This file tells VS Code: build a container from the official javascript-node:20 image (Node.js 20 preinstalled on a Debian base), give it the display name "My First Dev Container", and prepare port 3000 to be reachable from the host in case an app ends up running on it. Each field is broken down in detail in the next module.
(An alternate form exists — a .devcontainer.json file directly at the project root, no folder — but it stays rare in practice; the .devcontainer/ folder is the convention you'll run into almost everywhere.)
Step 3 — reopen in the container
In VS Code:
- Open the command palette:
Ctrl+Shift+P(Windows/Linux) orCmd+Shift+P(macOS) - Type
Dev Containers: Reopen in Containerand select that entry - VS Code will download the image (first time only — this can take several minutes depending on your connection), build the container, then relaunch the window inside it
You'll know it's in progress from a notification in the bottom right showing progress. Once done, the green bar in the bottom left of the window displays the Dev Container's name.
Step 4 — the proof you're inside
Open a terminal in VS Code (Ctrl+`). This terminal now runs inside the container, not on your machine. Verify it:
node --version
Expected output: a version of Node in the 20 branch, for example v20.18.1 — even if you don't have Node installed on your host machine, or have a different version. That's the proof: this version comes from the container's image, not from your system.
Second check, even more telling if you're on Windows or macOS:
cat /etc/os-release
Expected output: lines starting with PRETTY_NAME="Debian GNU/Linux ..." (or a Debian/Ubuntu variant depending on the image). If your host machine runs Windows or macOS, this command alone proves you're in a separate Linux environment — the container.
What you just did
You described an environment in a versionable file (devcontainer.json), asked VS Code to build it, and verified — through proof, not trust — that your terminal really runs inside it. This is exactly the mechanism that solves the "works on my machine" problem from the previous module: anyone else opening this same folder gets the same container, with the same Node version.
In the next module, you'll take this same JSON file and learn to read every field in it.
Check your understanding
In VS Code, what's the exact command to run from the command palette to open the project in the Dev Container?
Once the window has reopened inside the container, how can you be certain the terminal is really running inside the container and not on your host machine?
Where does the devcontainer.json file need to live for VS Code to detect it automatically?
Want to hear about the next modules?
The Academy stays free and open-access, no sign-up required. If you'd just like to be notified by email when a new module ships, here you go — no obligation, unsubscribe anytime with one click.