devcontainer
Develop projects in isolated, reproducible environments
TLDR
Create and run a Dev Container
Apply a Dev Container Template to a workspace
Execute a command on a running Dev Container in the current workspace
Build a Dev Container image from devcontainer.json
Open a Dev Container in VS Code (the path is optional)
Read and print the configuration of a Dev Container from devcontainer.json
SYNOPSIS
devcontainer command [options] [arguments]
Common commands:
devcontainer build [path] [options]
devcontainer open [path] [options]
devcontainer up [path] [options]
devcontainer exec [path] command [args...]
devcontainer read-configuration [path] [options]
devcontainer --version
devcontainer --help
PARAMETERS
command
The specific subcommand to execute (e.g., build, open, up, exec).
path
The path to the workspace folder containing the .devcontainer directory or devcontainer.json file. Defaults to the current working directory.
--help
Displays help information for the command or a specific subcommand.
--version
Shows the version of the Dev Containers CLI.
--workspace-folder
Explicitly specifies the root directory of the project to be opened or built in the dev container.
--log-level
Sets the verbosity of log output. Possible values include trace, debug, info, warn, error, fatal.
--skip-post-create
Prevents execution of the postCreateCommand defined in devcontainer.json when creating the container.
--container-id
(For open, exec) Connects to an already running container instance by its unique ID instead of starting a new one.
--remove-existing-container
(For up, build) If a container from a previous run exists for the specified workspace, it will be removed before a new one is created.
--no-cache
(For build) Instructs the container build process to not use any cached layers, forcing a fresh build.
DESCRIPTION
The devcontainer command-line interface (CLI) is an open-source tool that implements the Dev Containers specification. This specification defines a standard for creating and working with development environments inside containers. The CLI allows developers to build, open, and manage these development containers directly from their terminal, integrating seamlessly with various tools and workflows.
It provides functionalities to create containerized development environments based on a devcontainer.json file. This file specifies everything needed for a dev environment, including the base image or Dockerfile, tools, extensions, ports, and lifecycle scripts. The devcontainer CLI is essential for leveraging the benefits of dev containers: ensuring consistent development environments across teams, isolating dependencies, and simplifying onboarding for new developers. It supports various container runtimes like Docker and Podman.
Common use cases include opening a project in a dev container, building a dev container image, updating existing dev containers, and executing commands within them. It's often used in conjunction with IDEs like VS Code, which have built-in support for dev containers, but the CLI allows for headless or automated operations in CI/CD pipelines or scripting.
CAVEATS
The devcontainer CLI requires a compatible container runtime such as Docker or Podman to be installed and running on the host system.
The proper functioning of the command heavily relies on the presence and correct configuration of a devcontainer.json file within the project's .devcontainer directory.
Performance can vary significantly based on host system resources, container image size, and network conditions for image pulls.
Security implications should be considered when mounting host volumes or running untrusted code within a dev container.
THE <I>DEVCONTAINER.JSON</I> FILE
This JSON-formatted file is the central configuration for a dev container. It resides in a .devcontainer folder at the root of a project and defines all aspects of the development environment, including the base image or Dockerfile, required VS Code extensions, port forwarding rules, mount points, environment variables, and lifecycle scripts (postCreateCommand, postStartCommand, etc.). It ensures reproducibility and consistency across different development setups.
INTEGRATION WITH IDES
While a powerful standalone CLI, devcontainer is designed to work seamlessly with integrated development environments (IDEs) that support the Dev Containers specification. Most notably, VS Code has deep integration, allowing users to open local folders directly within a dev container, install extensions, debug applications, and manage the container's lifecycle directly from the IDE's interface. This tight integration enhances developer productivity by abstracting away the container management complexities.
DEV CONTAINERS SPECIFICATION
The devcontainer CLI is an implementation of the Dev Containers specification, which is an open, vendor-neutral standard. This specification promotes interoperability, allowing tools and platforms from different providers to create, manage, and interact with dev container configurations in a consistent manner. It aims to standardize the way cloud-native development environments are defined and consumed, fostering an ecosystem of compatible tools and services.
HISTORY
The concept of development containers originated from Microsoft's VS Code Remote - Containers extension, which enabled developers to use VS Code inside a containerized environment. Recognizing the broader utility and need for a standardized approach, the underlying technology evolved into the Dev Containers specification, an open standard for defining container-based development environments. The devcontainer CLI was then developed as an open-source implementation of this specification, providing a versatile command-line tool for managing these environments independently of any specific IDE. Its development is community-driven under the guidance of the Dev Containers open-source project.