Define the tooling, runtimes, and settings that power each remote workspace
brew
, apt
, or npm install
, think of a devcontainer as an automated, shareable version of those steps.
Looking for a deeper dive? See the official GitHub guide “Introduction to dev containers”.
.devcontainer/
in the root of your repository and add a file named devcontainer.json
.
devcontainer.json
sets up Node 20, installs dependencies, and forwards port 3000.
npm run dev
without installing Node locally.
Language | Snippet |
---|---|
Python | { "image": "mcr.microsoft.com/devcontainers/python:3.12", "postCreateCommand": "pip install -r requirements.txt" } |
Go | { "image": "mcr.microsoft.com/devcontainers/go:1.22-bullseye", "postCreateCommand": "go mod download" } |
Rust | { "image": "mcr.microsoft.com/devcontainers/rust:1-bullseye", "features": { "llvm": "latest" } } |
forwardPorts
. Factory detects them and shows friendly previews:
postCreateCommand
to install dev dependencies so teammates (and future you) don’t forget a step.devcontainer up
on your machine before pushing.README_REMOTE_WORKSPACE.md
that lists useful commands like npm test
or pytest
.Issue | Fix |
---|---|
Build takes forever | Start from a lighter base image or cache heavy tools in the image stage. |
Command not found | Make sure it’s installed in postCreateCommand or included in the base image. |
Port not visible | Confirm the app binds to 0.0.0.0 and that the port is in forwardPorts . |