LinuxCommandLibrary

devcontainer

Develop projects in isolated, reproducible environments

TLDR

Create and run a Dev Container

$ devcontainer up
copy

Apply a Dev Container Template to a workspace
$ devcontainer templates apply [[-t|--template-id]] [template_id] [[-a|--template-args]] [template_args] [[-w|--workspace-folder]] [path/to/workspace]
copy

Execute a command on a running Dev Container in the current workspace
$ devcontainer exec [command]
copy

Build a Dev Container image from devcontainer.json
$ devcontainer build [path/to/workspace]
copy

Open a Dev Container in VS Code (the path is optional)
$ devcontainer open [path/to/workspace]
copy

Read and print the configuration of a Dev Container from devcontainer.json
$ devcontainer read-configuration
copy

SYNOPSIS

devcontainer [GLOBAL_OPTIONS] <COMMAND> [<ARGS>]

PARAMETERS

-w, --workspace-folder <DIR>
    Path to workspace folder (default: current directory)

--config <PATH>
    Path to devcontainer.json config file

--image-name <NAME>
    Custom name for built image

--container-name <NAME>
    Custom name for container

-n, --log-level <LEVEL>
    Logging level: debug|info|warn|error (default: info)

--verbose
    Enable verbose logging

--remove-on-stop
    Remove container on stop

--env-file <PATH>
    Load environment variables from file

--accept-defaults
    Accept all prompts with defaults

-h, --help
    Print help information

-v, --version
    Print version

DESCRIPTION

The devcontainer command-line tool enables developers to build, run, and manage development containers defined via devcontainer.json configuration files. These containers provide reproducible, isolated development environments using Docker or compatible runtimes like Podman.

Key workflows include creating workspace-mounted containers (up), building custom images (build), executing commands (exec or run), stopping (stop or down), and viewing logs. It supports features like installing extensions, running tests, and using templates or features for quick setups.

Ideal for CI/CD, team onboarding, or local dev without VS Code GUI. Operates on workspace folders containing .devcontainer dirs, ensuring consistent tooling (languages, runtimes, extensions) across machines. Integrates with GitHub Codespaces and supports overrides for flexibility.

CAVEATS

Requires Docker/Podman and Node.js. Not installed by default; global install via npm. Subcommands like up, build have additional options shown via devcontainer <COMMAND> --help. Config must be in .devcontainer/devcontainer.json.

COMMON SUBCOMMANDS

up: Create/start container.
build: Build image.
exec: Run command in container.
down: Stop/delete.

INSTALLATION

npm install -g @devcontainers/cli
Or Docker: docker run -it --rm -v ${PWD}:/workdir mcr.microsoft.com/devcontainers/cli:0.XXX

HISTORY

Developed by Microsoft for VS Code Remote - Containers extension (2019). Standalone CLI (@devcontainers/cli) released 2022 via npm, supporting open Dev Container spec for cross-tool use.

SEE ALSO

docker(1), podman(1), code(1)

Copied to clipboard