Convert Figma logo to code with AI

devcontainers logocli

A reference implementation for the specification that can create and configure a dev container from a devcontainer.json.

1,469
206
1,469
216

Top Related Projects

NOTE: Most of the contents of this repository have been migrated to the new devcontainers GitHub org (https://github.com/devcontainers). See https://github.com/devcontainers/template-starter and https://github.com/devcontainers/feature-starter for information on creating your own!

12,708

The developer platform for on-demand cloud development environments to create software faster and more securely.

4,075

A development tool for all your projects that is fast, easy, powerful and liberating

3,235

Develop your applications directly in your Kubernetes Cluster

Podman Desktop - A graphical tool for developing on containers and Kubernetes

Quick Overview

The devcontainers/cli repository is a command-line interface (CLI) for working with development containers. It provides tools for creating, managing, and interacting with containerized development environments, making it easier for developers to set up consistent and reproducible workspaces across different machines and projects.

Pros

  • Simplifies the process of creating and managing development containers
  • Enhances consistency across different development environments
  • Integrates well with Visual Studio Code and other development tools
  • Supports multiple container technologies, including Docker and Kubernetes

Cons

  • May have a learning curve for developers new to containerization
  • Requires additional system resources to run containers
  • Can be complex to set up for more advanced scenarios
  • Limited documentation for some advanced features

Code Examples

  1. Creating a dev container configuration:
{
  "name": "Node.js",
  "image": "mcr.microsoft.com/devcontainers/javascript-node:0-18",
  "features": {
    "ghcr.io/devcontainers/features/node:1": {}
  }
}
  1. Running a command in a dev container:
devcontainer exec --workspace-folder /path/to/project npm install
  1. Building and running a dev container:
devcontainer up --workspace-folder /path/to/project

Getting Started

To get started with devcontainers/cli:

  1. Install the CLI:

    npm install -g @devcontainers/cli
    
  2. Create a .devcontainer folder in your project root and add a devcontainer.json file:

    {
      "name": "My Dev Container",
      "image": "mcr.microsoft.com/devcontainers/base:ubuntu"
    }
    
  3. Build and start the dev container:

    devcontainer up --workspace-folder .
    
  4. Execute commands in the container:

    devcontainer exec --workspace-folder . <your-command>
    

Competitor Comparisons

NOTE: Most of the contents of this repository have been migrated to the new devcontainers GitHub org (https://github.com/devcontainers). See https://github.com/devcontainers/template-starter and https://github.com/devcontainers/feature-starter for information on creating your own!

Pros of vscode-dev-containers

  • More comprehensive set of pre-built development container definitions
  • Tighter integration with VS Code, including UI elements and settings
  • Extensive documentation and examples for various development scenarios

Cons of vscode-dev-containers

  • Primarily focused on VS Code, limiting flexibility for other environments
  • Larger repository size due to extensive collection of container definitions
  • May include unnecessary components for simpler development setups

Code Comparison

vscode-dev-containers:

{
  "name": "Node.js",
  "build": {
    "dockerfile": "Dockerfile",
    "args": { "VARIANT": "14" }
  },
  "settings": { 
    "terminal.integrated.shell.linux": "/bin/bash"
  },
  "extensions": ["dbaeumer.vscode-eslint"]
}

cli:

{
  "image": "mcr.microsoft.com/devcontainers/javascript-node:0-14",
  "customizations": {
    "vscode": {
      "settings": { 
        "terminal.integrated.defaultProfile.linux": "bash"
      },
      "extensions": ["dbaeumer.vscode-eslint"]
    }
  }
}

The cli repository focuses on providing a standalone CLI tool for working with dev containers, offering greater flexibility across different environments and editors. It has a smaller footprint and is more modular, allowing for easier integration into various workflows and CI/CD pipelines. However, it may require more manual configuration for complex scenarios compared to the pre-built definitions in vscode-dev-containers.

12,708

The developer platform for on-demand cloud development environments to create software faster and more securely.

Pros of Gitpod

  • Provides a complete cloud-based development environment
  • Offers prebuilt workspaces for faster startup times
  • Integrates seamlessly with popular version control platforms

Cons of Gitpod

  • Requires internet connectivity for development
  • May have limitations on resource allocation in free tier
  • Learning curve for users new to cloud-based development environments

Code Comparison

Gitpod configuration (.gitpod.yml):

image: gitpod/workspace-full
tasks:
  - init: npm install
    command: npm run dev
ports:
  - port: 3000
    onOpen: open-preview

DevContainers CLI configuration (devcontainer.json):

{
  "image": "mcr.microsoft.com/devcontainers/javascript-node:0-18",
  "postCreateCommand": "npm install",
  "forwardPorts": [3000],
  "customizations": {
    "vscode": {
      "extensions": ["dbaeumer.vscode-eslint"]
    }
  }
}

Both configurations define development environments, but Gitpod focuses on cloud-based setups, while DevContainers CLI is more flexible for local and remote development. Gitpod's configuration is typically simpler, while DevContainers offers more customization options for VS Code integration.

4,075

A development tool for all your projects that is fast, easy, powerful and liberating

Pros of Lando

  • More comprehensive tooling ecosystem with built-in support for popular frameworks and CMSs
  • Easier setup for complex multi-service environments
  • Provides a GUI for managing projects and services

Cons of Lando

  • Steeper learning curve due to its extensive feature set
  • Larger footprint and potentially slower startup times
  • Less integrated with code editors compared to devcontainers

Code Comparison

Lando configuration (.lando.yml):

name: myapp
recipe: drupal9
config:
  webroot: web
  database: mysql:5.7

Devcontainers configuration (devcontainer.json):

{
  "name": "PHP",
  "image": "mcr.microsoft.com/devcontainers/php:0-8.2",
  "features": {
    "ghcr.io/devcontainers/features/node:1": {}
  }
}

Lando focuses on pre-configured recipes for specific stacks, while devcontainers provides a more flexible, language-agnostic approach. Lando's configuration is typically more concise for complex setups, but devcontainers offers greater customization potential and closer integration with development environments.

3,235

Develop your applications directly in your Kubernetes Cluster

Pros of Okteto

  • Designed for Kubernetes-native development, offering seamless integration with K8s clusters
  • Provides a complete development platform with built-in collaboration features
  • Supports remote development environments with automatic synchronization

Cons of Okteto

  • Steeper learning curve for developers not familiar with Kubernetes
  • May be overkill for simple projects or non-containerized applications
  • Requires more resources and setup compared to lightweight alternatives

Code Comparison

Okteto:

deploy:
  - okteto build -t okteto.dev/myapp:${OKTETO_GIT_COMMIT} .
  - kubectl apply -f k8s.yml

DevContainers CLI:

{
  "name": "My Dev Container",
  "image": "mcr.microsoft.com/devcontainers/base:ubuntu",
  "features": {
    "ghcr.io/devcontainers/features/node:1": {}
  }
}

Key Differences

  • Okteto focuses on Kubernetes-centric development, while DevContainers CLI is more general-purpose
  • Okteto offers a full-fledged development platform, whereas DevContainers CLI is primarily for container configuration
  • DevContainers CLI integrates well with VS Code and GitHub Codespaces, while Okteto has its own ecosystem

Use Cases

  • Choose Okteto for Kubernetes-native development and team collaboration
  • Opt for DevContainers CLI for simpler containerized development environments and better VS Code integration

Podman Desktop - A graphical tool for developing on containers and Kubernetes

Pros of Podman Desktop

  • Provides a user-friendly graphical interface for container management
  • Supports multiple container engines (Podman, Docker, Lima)
  • Offers a more comprehensive container ecosystem management solution

Cons of Podman Desktop

  • Larger resource footprint due to GUI components
  • May have a steeper learning curve for users familiar with CLI-only tools
  • Less suitable for automated workflows or scripting compared to CLI tools

Code Comparison

Podman Desktop (JavaScript/TypeScript):

import { ContainerEngine } from './container-engine';

export class PodmanEngine extends ContainerEngine {
  async listContainers() {
    // Implementation for listing Podman containers
  }
}

DevContainers CLI (TypeScript):

import { ContainerRuntime } from './container-runtime';

export class DevContainer {
  constructor(private runtime: ContainerRuntime) {}

  async start() {
    // Implementation for starting a dev container
  }
}

Summary

Podman Desktop offers a more comprehensive GUI-based solution for container management, supporting multiple engines and providing a user-friendly interface. DevContainers CLI, on the other hand, focuses on a lightweight, command-line approach specifically tailored for development environments. The choice between the two depends on user preferences, workflow requirements, and the need for graphical interfaces versus command-line efficiency.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Dev Container CLI

This repository holds the dev container CLI, which can take a devcontainer.json and create and configure a dev container from it.

Context

A development container allows you to use a container as a full-featured development environment. It can be used to run an application, to separate tools, libraries, or runtimes needed for working with a codebase, and to aid in continuous integration and testing. Dev containers can be run locally or remotely, in a private or public cloud.

Diagram of inner and outerloop development with dev containers

This CLI is in active development. Current status:

  • devcontainer build - Enables building/pre-building images
  • devcontainer up - Spins up containers with devcontainer.json settings applied
  • devcontainer run-user-commands - Runs lifecycle commands like postCreateCommand
  • devcontainer read-configuration - Outputs current configuration for workspace
  • devcontainer exec - Executes a command in a container with userEnvProbe, remoteUser, remoteEnv, and other properties applied
  • devcontainer features <...> - Tools to assist in authoring and testing Dev Container Features
  • devcontainer templates <...> - Tools to assist in authoring and testing Dev Container Templates
  • devcontainer stop - Stops containers
  • devcontainer down - Stops and deletes containers

Try it out

We'd love for you to try out the dev container CLI and let us know what you think. You can quickly try it out in just a few simple steps, either by installing its npm package or building the CLI repo from sources (see "Build from sources").

To install the npm package you will need Python and C/C++ installed to build one of the dependencies (see, e.g., here for instructions).

npm install

npm install -g @devcontainers/cli

Verify you can run the CLI and see its help text:

devcontainer <command>

Commands:
  devcontainer up                   Create and run dev container
  devcontainer build [path]         Build a dev container image
  devcontainer run-user-commands    Run user commands
  devcontainer read-configuration   Read configuration
  devcontainer features             Features commands
  devcontainer templates            Templates commands
  devcontainer exec <cmd> [args..]  Execute a command on a running dev container

Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]

Try out the CLI

Once you have the CLI, you can try it out with a sample project, like this Rust sample.

Clone the Rust sample to your machine, and start a dev container with the CLI's up command:

git clone https://github.com/microsoft/vscode-remote-try-rust
devcontainer up --workspace-folder <path-to-vscode-remote-try-rust>

This will download the container image from a container registry and start the container. Your Rust container should now be running:

[88 ms] dev-containers-cli 0.1.0.
[165 ms] Start: Run: docker build -f /home/node/vscode-remote-try-rust/.devcontainer/Dockerfile -t vsc-vscode-remote-try-rust-89420ad7399ba74f55921e49cc3ecfd2 --build-arg VARIANT=bullseye /home/node/vscode-remote-try-rust/.devcontainer
[+] Building 0.5s (5/5) FINISHED
 => [internal] load build definition from Dockerfile                       0.0s
 => => transferring dockerfile: 38B                                        0.0s
 => [internal] load .dockerignore                                          0.0s
 => => transferring context: 2B                                            0.0s
 => [internal] load metadata for mcr.microsoft.com/vscode/devcontainers/r  0.4s
 => CACHED [1/1] FROM mcr.microsoft.com/vscode/devcontainers/rust:1-bulls  0.0s
 => exporting to image                                                     0.0s
 => => exporting layers                                                    0.0s
 => => writing image sha256:39873ccb81e6fb613975e11e37438eee1d49c963a436d  0.0s
 => => naming to docker.io/library/vsc-vscode-remote-try-rust-89420ad7399  0.0s
[1640 ms] Start: Run: docker run --sig-proxy=false -a STDOUT -a STDERR --mount type=bind,source=/home/node/vscode-remote-try-rust,target=/workspaces/vscode-remote-try-rust -l devcontainer.local_folder=/home/node/vscode-remote-try-rust --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --entrypoint /bin/sh vsc-vscode-remote-try-rust-89420ad7399ba74f55921e49cc3ecfd2-uid -c echo Container started
Container started
{"outcome":"success","containerId":"f0a055ff056c1c1bb99cc09930efbf3a0437c54d9b4644695aa23c1d57b4bd11","remoteUser":"vscode","remoteWorkspaceFolder":"/workspaces/vscode-remote-try-rust"}

You can then run commands in this dev container:

devcontainer exec --workspace-folder <path-to-vscode-remote-try-rust> cargo run

This will compile and run the Rust sample, outputting:

[33 ms] dev-containers-cli 0.1.0.
   Compiling hello_remote_world v0.1.0 (/workspaces/vscode-remote-try-rust)
    Finished dev [unoptimized + debuginfo] target(s) in 1.06s
     Running `target/debug/hello_remote_world`
Hello, VS Code Remote - Containers!
{"outcome":"success"}

Congrats, you've just run the dev container CLI and seen it in action!

More CLI examples

The example-usage folder contains some simple shell scripts to illustrate how the CLI can be used to:

  • Inject tools for use inside a development container
  • Use a dev container as your CI build environment to build an application (even if it is not deployed as a container)
  • Build a container image from a devcontainer.json file that includes dev container features

Build from sources

This repository has a dev container configuration, which you can use to ensure you have the right dependencies installed.

Compile the CLI with yarn:

yarn
yarn compile

Verify you can run the CLI and see its help text:

node devcontainer.js --help

Specification

The dev container CLI is part of the Development Containers Specification. This spec seeks to find ways to enrich existing formats with common development specific settings, tools, and configuration while still providing a simplified, un-orchestrated single container option – so that they can be used as coding environments or for continuous integration and testing.

Learn more on the dev container spec website.

Additional resources

You may review other resources part of the specification in the devcontainers GitHub organization.

Documentation

Contributing

Check out how to contribute to the CLI in CONTRIBUTING.md.

License

This project is under an MIT license.

NPM DownloadsLast 30 Days