Architecture specification

Development Container

The authoritative development environment for a repository — reusable features provide the toolchains, and repository-specific lifecycle hooks finish the workspace.

Applies at
.devcontainer/
Status
Stable
Source · managed
.devcontainer/README.md

01 Defines

A container definition, following the Development Containers specification, that provisions every tool, runtime, service, and utility needed to work on the repository, so a fresh rebuild is ready for development without manual bootstrapping.

02 Applies when

  • A repository needs the same toolchain for every developer, editor, and automation surface.
  • Tools and services must be provisioned before any project command runs.
  • Common tooling can be expressed as reusable devcontainer features rather than hand-written installs.

03 Boundaries

  • Provisioning the environment is in scope; project operations such as restore, generate, build, and test are not.
  • Only tooling the repository owns or directly uses is provisioned; platform integration tooling only where that boundary is documented.
  • The configuration does not depend on one hosted editor or source-control provider.

Expected behaviour

  1. 01
    devcontainer.json declares settings, mounts, features, and one lifecycle command per phase.
  2. 02
    devcontainer-lock.json records the resolved version and digest of every feature.
  3. 03
    The Dockerfile stays minimal and delegates toolchain installation to features.
  4. 04
    Reusable toolchains come from devcontainer features; repository-specific setup comes from lifecycle scripts.
  5. 05
    Every lifecycle command delegates to the shared run-parts.sh runner.
  6. 06
    Any tool that can run the Dev Containers CLI can build and use the environment.

Behaviour#

The development container is responsible for the environment; the repository’s commands only use it. Developers are not expected to run a separate bootstrap step to install tools after the container is built — if a tool is needed, the container provides it.

The definition is layered. A small base image sets the operating system and primary runtime. Devcontainer features add reusable capabilities on top. The Devcontainer Lifecycle adds the last, repository-specific layer.

FlowLayers of the environment
  1. 01 Base image Dockerfile — one FROM line, kept minimal
  2. 02 Features Toolchains, CLIs, and services, pinned by devcontainer-lock.json
  3. 03 Container Mounts, remoteUser, containerEnv, and editor customisations
  4. 04 Lifecycle Repository-specific hooks run by run-parts.sh Devcontainer Lifecycle
  • .devcontainer/
  • devcontainer.json Settings, mounts, features, lifecycle commands
  • devcontainer-lock.json Resolved feature versions and digests
  • Dockerfile Base image; direct customisation kept minimal
  • lifecycle/ Shared runner and hook directories Devcontainer Lifecycle

Features first#

A devcontainer feature is the preferred way to install a common toolchain, configure a runtime dependency, or expose a development service. When a suitable upstream feature exists, it is used instead of re-implementing the install in a lifecycle script or the Dockerfile.

When no upstream feature fits, or organisation-specific behaviour is required, a local feature may be developed under ./features. It stays generic enough to be extracted and reused by other repositories later. Workspace initialisation, shell customisation, and other repository-specific behaviour stay out of features and belong in lifecycle scripts.

Tool versions may come from shared metadata such as .tool-versions, or be pinned directly in devcontainer or CI configuration. Where consistency matters, the pins are shared or coordinated.

Pinning#

devcontainer.json names each feature with a version tag such as :1. devcontainer-lock.json records what that resolved to — the exact version and content digest of every feature. Committing the lockfile is what makes the environment reproducible: a rebuild in a month gets the same features the container has today, even where the tag still resolves.

The same reasoning applies to the base image: a dated tag such as 2026.1029.6 pins the operating system and primary runtime to one build instead of floating with latest. Upgrades then happen as deliberate edits to the definition, not as side effects of a rebuild.

Mounts and environment#

Two pieces of devcontainer.json carry the state that surrounds the toolchain. Named-volume mounts keep developer configuration out of the rebuilt image — shell history, editor configuration, git identity, cloud credentials — so a rebuild refreshes the environment without discarding the person using it. containerEnv sets the variables the workspace and its tools agree on, such as the workspace path and the editor defaults.

In the image

  • The operating system and primary runtime
  • Toolchains installed by features
  • Anything two developers should never have to configure differently

In mounts and env

  • Git identity, cloud credentials, shell history
  • Editor and shell configuration
  • Values that differ per developer, such as the local timezone

Examples#

Every lifecycle command in this repository delegates to the same runner, toolchains arrive as features, and developer state rides in named volumes:

.devcontainer/devcontainer.json (excerpt)
{
  "build": { "dockerfile": "Dockerfile" },
  "remoteUser": "node",
  "mounts": [
    "source=devcontainer-git-config,target=/home/node/.config/git,type=volume",
    "source=devcontainer-aws-config,target=/home/node/.aws,type=volume",
    "source=devcontainer-ssh-config,target=/home/node/.ssh,type=volume"
  ],
  "initializeCommand": "bash .devcontainer/lifecycle/run-parts.sh initialize",
  "onCreateCommand": "bash .devcontainer/lifecycle/run-parts.sh on-create",
  "updateContentCommand": "bash .devcontainer/lifecycle/run-parts.sh update-content",
  "postCreateCommand": "bash .devcontainer/lifecycle/run-parts.sh post-create",
  "postStartCommand": "bash .devcontainer/lifecycle/run-parts.sh post-start",
  "postAttachCommand": "bash .devcontainer/lifecycle/run-parts.sh post-attach",
  "containerEnv": {
    "WORKSPACE": "${containerWorkspaceFolder}",
    "TZ": "${localEnv:TZ:America/Los_Angeles}",
    "EDITOR": "nano"
  },
  "features": {
    "ghcr.io/devcontainers-extra/features/starship:1": {},
    "ghcr.io/devcontainers-extra/features/fzf:1": {},
    "ghcr.io/devcontainers-extra/features/eza:1": {},
    "ghcr.io/devcontainers-extra/features/ripgrep:1": {}
  }
}

The environment is driven entirely from the Dev Containers CLI, so any editor or automation surface can wrap the same commands:

devcontainer up --workspace-folder .                  # Build and start
devcontainer exec --workspace-folder . make doctor    # Verify the environment
devcontainer exec --workspace-folder . make validate  # Run project validation
devcontainer build --workspace-folder .               # Prebuild or warm the cache

make doctor is the Environment Doctor : it reports what the container was expected to provide and what is missing.