Author : MD TAREQ HASSAN | Updated : 2023/07/24
Inroduction
- The
devcontainer.json
file is a central configuration file used in Devcontainers - It plays a crucial role in defining the development environment and specifying various settings for the isolated development environment
- It defines the development environment, specifying the base container image, required tools, extensions, and settings for the development environment
- This file can be shared across the development team to ensure consistency
- This file is typically placed in the root directory of the project and
devcontainer.json
is used to set up the development environment automatically
Note: A tool supporting the dev container specification is required to build a development container.
Explanation
devcontainer.json
{
"name": "Node.js & TypeScript",
"image": "mcr.microsoft.com/devcontainers/typescript-node",
"features": {
"ghcr.io/devcontainers/features/azure-cli:1": {},
"ghcr.io/devcontainers/features/powershell:1": {}
},
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.defaultProfile.linux": "bash"
},
"extensions": [
"oderwat.indent-rainbow"
]
}
}
// "forwardPorts": [],
// "postCreateCommand": "yarn install",
}
name
: A name for the dev container displayed in the UIimage
:- Required when using an image is used to create the dev container
- Name of an image in a container registry i.e. DockerHub, GitHub Container Registry (ghcr), Azure Container Registry
features
: An object of Dev Container Feature IDs and related options to be added into your primary containercustomizations
: Product specific properties, defined in supporting tools
Links
- General
devcontainer.json
properties: https://containers.dev/implementors/json_reference/#general-properties - Image or Dockerfile specific properties: https://containers.dev/implementors/json_reference/#image-specific
- Docker Compose specific properties: https://containers.dev/implementors/json_reference/#compose-specific
- Supporting tools and services: https://containers.dev/supporting
- Lifecycle scripts: https://containers.dev/implementors/json_reference/#lifecycle-scripts
- Port attributes: https://containers.dev/implementors/json_reference/#port-attributes
- Instead of image, use a Dockerfile or Docker Compose file: https://containers.dev/guide/dockerfile