Search

Search IconIcon to open search

Devcontainers (`devcontainer.json`)

Last updatedUpdated: by Simon Späti · CreatedCreated: · 3 min read

The Visual Studio Code Dev Containers extension lets you use a  Docker container as a full-featured development environment. It allows you to open any folder or repository inside a container and take advantage of Visual Studio Code’s full feature set.

devcontainer.json file in your project tells VS Code how to access (or create) a development container with a well-defined tool and runtime stack. This container can be used to run an application or to provide separate tools, libraries, or runtimes needed for working with a codebase.

# Path to creating a dev container

In this document, we’ll go through the steps for creating a development (dev) container in VS Code:

  1. Create a devcontainer.json, which describes how VS Code should start the container and what to do after it connects.
  2. Make and persist changes to the dev container, such as installation of new software, through use of a Dockerfile.
  3. Configure multiple containers through Docker Compose.
  4. As you make changes, build your dev container to ensure changes take effect.

After any of the steps above, you’ll have a fully functioning dev container, and you can either continue to the next step of this tutorial to add more features, or stop and begin working in the dev environment you currently have.

# System Requirements

Local / Remote Host:

You can use Docker with the Dev Containers extension in a few ways, including:

  • Docker installed locally.
  • Docker installed on a remote environment.
  • Other Docker compliant CLIs, installed locally or remotely.

You can learn more in the  alternative Docker options doc.

Below are some specific ways you can configure Docker on a local or remote host:

  • Windows:  Docker Desktop 2.0+ on Windows 10 Pro/Enterprise. Windows 10 Home (2004+) requires Docker Desktop 2.3+ and the  WSL 2 back-end. (Docker Toolbox is not supported. Windows container images are not supported.)
  • macOSDocker Desktop 2.0+.
  • LinuxDocker CE/EE 18.06+ and  Docker Compose 1.21+. (The Ubuntu snap package is not supported.)
  • Remote hosts: 1 GB RAM is required, but at least 2 GB RAM and a 2-core CPU is recommended.

Containers:

  • x86_64 / ARMv7l (AArch32) / ARMv8l (AArch64) Debian 9+, Ubuntu 16.04+, CentOS / RHEL 7+
  • x86_64 Alpine Linux 3.9+

Other glibc based Linux containers may work if they have  needed Linux prerequisites.

More on Installation.

# devcontainer.json

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile
{
	"name": "Existing Dockerfile",
	"build": {
		// Sets the run context to one level up instead of the .devcontainer folder.
		"context": "..",
		// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
		"dockerfile": "../Dockerfile"
	}

	// Features to add to the dev container. More info: https://containers.dev/features.
	// "features": {},

	// Use 'forwardPorts' to make a list of ports inside the container available locally.
	// "forwardPorts": [],

	// Uncomment the next line to run commands after the container is created.
	// "postCreateCommand": "cat /etc/os-release",

	// Configure tool-specific properties.
	// "customizations": {},

	// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
	// "remoteUser": "devcontainer"
}

# Example with VSCode

Start CODING IN MINUTES with DevContainers - YouTube

# with Neovim

# Starting Devcontainers

Devpod seems to be able to start Devcontainers. It’s like Github Codespaces, but open-source.

See example in Workspaces.


Origin: