devcontainer.json file to define a consistent, fully featured development workspace. A dev container is a Docker container configured to provide a reproducible environment that includes the operating system, runtimes, tooling, VS Code extensions, and automated setup steps.
In GitHub Codespaces, each session runs inside one of these containers on a high-performance VM. By defining your environment as code, every developer—regardless of their local setup—gets the exact same tools, runtimes, and editor settings.
Here is a representative devcontainer.json (JSON with comments / JSONC) showing common configuration options:
- Reproducibility: Everyone uses the same base image, runtime, and extensions.
- Onboarding: New contributors can start coding without manual environment setup.
- CI parity: You can match local development containers to CI images to reduce “works on my machine” issues.
- Place the
devcontainer.jsonfile in the repository root under.devcontainer/(for example.devcontainer/devcontainer.json). Both GitHub Codespaces and VS Code Remote - Containers look here to build the workspace container.
devcontainer.json
Lifecycle hooks and when to use them
Example: when to use
postCreateCommand vs postStartCommand
- Use
postCreateCommandfor one-time setup tasks that should only run when the container is first built (for example,npm installor generating boilerplate files). - Use
postStartCommandfor tasks that should run whenever the container starts (for example, starting a local database or a background watcher).
Do not store secrets (API keys, passwords) directly in
devcontainer.json or committed scripts. Use environment variables provided by Codespaces, GitHub Actions secrets, or other secret-management tools to inject sensitive values at runtime.- Use the Dev Container Features registry to add common tooling quickly (GitHub CLI, Docker CLI, Python, Node.js, terraform, etc.).
- Extensions listed under
customizations.vscode.extensionswill be automatically installed for anyone opening the container—this ensures team-wide consistency for linters, formatters, and language tooling.
Dev container configuration files are JSONC (JSON with comments). To keep the
devcontainer.json concise and maintainable, put longer or sensitive setup logic into scripts in the repository (for example, scripts/setup.sh) and invoke them from postCreateCommand or other hooks.- A
devcontainer.jsonmakes your development environment portable and reproducible across machines and Codespaces. - Store it in
.devcontainer/devcontainer.jsonand use it to define the base image or Dockerfile, editor customizations, forwarded ports, lifecycle hooks, and optional features. - In GitHub Codespaces, this file instructs Codespaces how to build each workspace container so every team member has the same environment.
- Dev Containers documentation (Microsoft)
- GitHub Codespaces
- Dev Container Features registry
- GitHub CLI