Circuit Times
Subscribe

Dev Containers Guide: How to Set One Up, With a Lab Run You Can Repeat

Dev containers explained: devcontainer.json, Reopen in Container in VS Code, the CLI, Features and a real lab run.

  • 20 min read
  • 18 sections
  • Published November 26, 2026
Rafael Ondrejka

How-to

A dev container is a container that holds your development tools, described by a file named devcontainer.json that lives in the project. Open the project in a supporting editor and teammates can use the same defined development environment.

To start in VS Code you need Docker, VS Code, the Microsoft Dev Containers extension and a project containing a .devcontainer/devcontainer.json file.

This guide explains the file, the VS Code steps and the command line tool. It also reports a lab run of 13 small tests, with the exact files and the transcript in a download.

A disclosure comes first. Circuit Times used Claude, an AI model made by Anthropic, to help prepare this article and to run the lab. Circuit Times is responsible for the tests, the evidence package and the conclusions.

The short answer

  • A dev container is a container plus a config file. That file names the image, the user account and the setup commands, so any supporting tool can build the same environment.
  • Docker still does the work. You need Docker, or a compatible engine, on your machine or on a remote host. Dev containers add a layer of project settings on top.
  • In VS Code the key command is Reopen in Container. It comes with Microsoft’s Dev Containers extension and builds or starts the container, then connects the editor to it.
  • You do not need VS Code. The Dev Container CLI reads the same file. In my lab it started a working container from one command.
  • Three things surprised me in the lab. The CLI did not publish a forwardPorts port, the GitHub CLI Feature failed on an Alpine image, and the CLI’s README marked its stop command as not yet implemented.

What I checked, and what I did not

I saved 14 source pages on November 20, 2026 and wrote down 9 records of what they say. A script, described near the end, verifies 51 selected evidence passages against their saved source text.

Kind of sourcePagesWhat it gives
Development Containers specification site5The file format, lifecycle commands, Features and the list of supporting tools
Vendor documentation7VS Code, GitHub Codespaces and Claude Code instructions
Open source project files2The CLI’s README and one Feature’s install script
Total14

I also ran a lab. It used Dev Container CLI 0.90.0 and Docker 29.10.0 on a Linux machine, as a normal user with user ID 1001. The base image was mcr.microsoft.com/devcontainers/base:alpine.

I ran the lab on November 20, 2026 and again on November 25, 2026, after rewriting its cleanup step and adding assertions.

I did not test the VS Code interface, macOS, Windows, Docker Desktop, Podman, GitHub Codespaces, Cursor, JetBrains editors, Docker Compose setups or the Claude Code Feature. Statements about those come from the linked documentation, not from my own run.

What a dev container is

The specification overview describes a development container as the place where you write and test an application, ahead of any deployment. It is a working environment, not the image you ship.

The config file is devcontainer.json. The specification calls it a metadata format, written as JSON that allows comments, where tools keep their settings for coding in containers.

GitHub’s Codespaces documentation says the file is usually located in the .devcontainer directory of your repository. It can also sit in the repository root, where its name must begin with a period: .devcontainer.json.

The format is an open specification, so several tools read it. The specification’s supporting tools page lists Visual Studio Code, Visual Studio, IntelliJ IDEA and Emacs as editors, and GitHub Codespaces as a service.

Dev containers vs Docker

Dev containers do not replace Docker. They describe how to use a container for development. The specification says the CLI gives more power than a plain docker build and docker run because it applies Features and runs lifecycle scripts.

The dev container column summarizes the metadata reference and the VS Code documentation. It describes defaults, which a project can change, and tools differ in what they support.

QuestionPlain DockerDev container
Where do the settings live?In command flags, a Dockerfile or a Compose fileIn devcontainer.json, which can point at an image, a Dockerfile or a Compose file
Who mounts the project folder?You, with a volume flagVS Code default: the workspace folder is mounted into the container. The file can change the mount, and other tools may differ
Which user runs your commands?The image default unless you set oneThe remoteUser for the tool’s own processes, such as terminals and tasks. The container’s own user stays whatever the image or containerUser sets
What runs after creation?Nothing unless you script itLifecycle commands such as postCreateCommand
How do editors connect?You set that upAn editor that supports it connects. VS Code installs and runs extensions inside the container

My lab shows the difference in a small way. I started the same image with plain docker run and mounted the same folder.

The user was root, the variable from the file was empty and the post-create file did not exist.

user: root
folder: /src
DEMO_MODE: []
cannot access '/tmp/post-create.txt': No such file or directory

What you need before you start

The VS Code documentation lists the requirements for its extension. These are the documented minimums, and I did not test them.

SystemDocumented requirement
WindowsWindows 10 Pro or Enterprise with Docker Desktop 2.0 or newer. Windows 10 Home needs build 2004 or later, Docker Desktop 2.3 or newer and the WSL 2 back end
macOSDocker Desktop 2.0+
LinuxDocker CE/EE 18.06+ and Docker Compose 1.21+
Remote hostsA minimum of 1 GB of memory. The documentation recommends 2 GB or more and two CPU cores

The same page says other Docker compliant command line tools may work but are not officially supported. Docker Desktop has its own licence rules for companies, so read Docker’s terms before using it at work.

How to set up dev containers in VS Code

These steps follow Microsoft’s documentation. I did not run the VS Code interface, so treat the menu names as the documentation’s, not as my observation.

  1. Get Docker installed, then confirm the Docker engine has started.
  2. Add the Dev Containers extension to VS Code. Its identifier is ms-vscode-remote.remote-containers.
  3. Open your project folder in VS Code.
  4. Add a .devcontainer/devcontainer.json file. You can write it by hand or let the extension add configuration files from a template.
  5. Press F1 for the Command Palette, then choose Dev Containers: Reopen in Container.
  6. Wait while the image downloads or builds. VS Code then reloads, connected to the container.

What Reopen in Container does

Per the VS Code documentation, VS Code reads devcontainer.json to learn how to reach or build a development container that carries a set toolchain and runtime.

It adds that your project files reach the container in one of three ways: a mount from your disk, a copy, or a clone.

Extensions get installed in the container and execute there, so they can use its tools and files directly.

After you change the configuration, the specification’s tools page gives one tip: run Dev Containers: Rebuild Container from the Command Palette to pick up the change.

A first devcontainer.json, and what happened when I ran it

This is the first file from the lab. It uses a ready-made image, sets one environment variable, asks for one port, runs one command after creation and names the user.

{
  "name": "circuit-times-demo",
  "image": "mcr.microsoft.com/devcontainers/base:alpine",
  "containerEnv": { "DEMO_MODE": "inside-container" },
  "forwardPorts": [8000],
  "postCreateCommand": "echo created > /tmp/post-create.txt",
  "remoteUser": "vscode"
}

I started it with the CLI and then ran a few commands inside. The transcript shows the user from the file, the project mounted under /workspaces, the variable set and the post-create command already finished.

user: vscode uid 1001
folder: /workspaces/demo
files: hello.py
DEMO_MODE: inside-container
post-create file: created

Notice the user ID. Inside the container the vscode user had ID 1001, the same as my user on the host.

According to the specification’s metadata reference, Linux hosts get special handling: the container user’s numeric IDs are changed to equal those of your local account, which keeps bind mounted files writable.

That showed in the files. A file I wrote on the host was readable inside. One created inside the container showed up on the host under user ID 1001.

edited on the host
written in the container
owner uid on host: 1001

With the image already downloaded, the three timed starts in the transcript took between 1 and 3 seconds each, rounded to whole seconds. A first run also has to download the image, which I did not time.

How to use the Dev Container CLI

The CLI is the specification’s reference implementation. Its README describes the job plainly: read a devcontainer.json, then build a dev container and set it up to match.

The README gives two install routes: an install script for Linux and macOS, and the npm package. I used the npm package inside a project folder. The global form from the README is this.

npm install -g @devcontainers/cli

Two commands cover daily use. The first creates and starts the container. The second runs a command inside it with the settings from the file applied.

devcontainer up --workspace-folder .
devcontainer exec --workspace-folder . bash

At the time of testing, the README’s status list marks devcontainer stop and devcontainer down as not done yet. I had CLI 0.90.0 installed, and a later version may add them.

In the lab I stopped and removed containers with Docker itself. The CLI labels each container with the project folder, which makes them easy to find.

devcontainer.config_file
devcontainer.local_folder
devcontainer.metadata

The cleanup step works only on container IDs that the script itself recorded. It never searches by label or name, and it checks afterwards that each recorded container is really gone.

The script copies the six projects into a new private folder with a random name and starts every container from there.

The CLI labels a container with its folder path. The random private path helps distinguish this run’s containers from containers using other project folders.

It records a container’s ID only when the container passes three identity checks.

Immediately before each start, the script checks that every container already carrying the folder label has an ID recorded by this run.

Then the CLI must report success, and the returned container must carry this run’s folder and config file labels.

Before the first test, the script also checks that no container already uses one of its folders. If that check fails, it stops and starts nothing.

To show the cleanup is narrow, the last test starts an unrelated container that carries the same label for a different folder. It has no name, and the script keeps the ID Docker returns.

After cleanup that container was still running. The script removes it by its saved ID when it exits.

unrelated container created: yes
lab containers found: 5
lab containers left: 0
unrelated container still present: 1
project files left: from-container.txt hello.py note.txt

Five containers were found, not six, because the sixth project is the Feature build that failed and never produced a container.

Removing the containers did not touch the project. The three files in the project folder were still there, because they live on the host and are only mounted into the container.

An earlier version of the script removed every container that had this label, which could have deleted other projects’ dev containers. I changed it before publication and reran the whole lab.

Every test now asserts its result. The script compares what it saw with the expected value, and stops with a nonzero exit status at the first mismatch. The Feature test must fail, and for the apt-get reason.

Six safety tests check the script itself. They are in lab/safety_tests.sh, each asserts its own result, and their output is in lab-safety-tests.txt in the download.

Safety testWhat it doesResult
Container already existsStarts a container with the exact label of a lab folder, then runs the labThe lab refused to start. The other container was still present
Second processStarts a container with that label while the lab is running, after the Feature testThe lab finished normally. The other container was still present
Adopted containerMakes the CLI return another process’s container that carries only the folder label, and report successThe lab rejected it, removed only its own containers and exited with status 1
Broken testBreaks the Dockerfile for the build testThe lab exited with status 1 at that test. None of its containers were left
Killed during a startSends a signal after Docker first lists the ports container while devcontainer up is still running, with another process’s container on the same labelThe lab exited with status 130 and left the unverified container for manual inspection. The other container was still present
Removal failsReplaces docker rm with a version that always failsThe lab printed CLEANUP FAILED, named six containers and exited with status 3

The killed run shows the one case the script will not clean up. If a run stops before devcontainer up has returned, the script has no checked ID for that container.

It cannot show that container is its own, so it leaves it. It prints POSSIBLE LEFTOVER, names the folder and gives the command to inspect it. One unverified container was left in that test, as designed.

One limit remains, and the adopted test does not cover it. Labels are not ownership credentials. A foreign container carrying both of the CLI’s labels for the same private folder is indistinguishable from the lab’s own container.

This could happen if another Dev Container CLI process uses that folder concurrently, or if another process creates a container with those labels. The script could remove that foreign container.

Ports: forwardPorts and appPort

In the metadata reference, forwardPorts is a list of container ports a tool must always pass through to your own machine. VS Code’s documentation adds that the forwarding starts once VS Code has connected to the container.

With the CLI alone, nothing connected, and Docker reported no published port for the container that asked for forwardPorts.

docker port output: []

VS Code’s documentation describes a second option, appPort, which publishes a port when the container is created. I tried it in a second project and Docker showed the port, bound to the local address.

docker port output: [8000/tcp -> 127.0.0.1:8000]

appPort publishes a container port to the host through Docker’s port mapping. The host address it binds to depends on that mapping. In my run Docker bound it to 127.0.0.1, the loopback address of the same machine.

Two separate settings are involved. One is Docker’s binding on the host side, which was 127.0.0.1 in my run. The other is the address the application listens on inside the container.

The documentation’s warning is about the second one. To the application, traffic on a forwarded port seems to come from localhost. A published port arrives as a network call instead.

So, the documentation says, an application that accepts only localhost calls will reject it. Here localhost means the loopback address inside the container, not the host’s 127.0.0.1.

I did not run an application server in this lab. The host binding is my observation. The behavior of an application behind a published port is documented, not tested.

The specification recommends forwardPorts in most cases. My finding is narrower and covers only the CLI-only setup I tested. With no editor attached, forwardPorts did not open a port. I did not test how VS Code forwards ports.

Lifecycle commands, in the order they ran

The specification defines six command properties. One runs on the host and five run inside the container. I gave each a command that appends its own name to a file.

CommandWhere it runsWhen the metadata reference says it runs
initializeCommandHostWhile the tool initializes: when the container is first created and again on every later start
onCreateCommandContainerRight after the container’s first ever start
updateContentCommandContainerNext after onCreateCommand, when creation finds fresh content in the source tree
postCreateCommandContainerNext after updateContentCommand, the first time a user is given the container
postStartCommandContainerOn every successful start of the container
postAttachCommandContainerOn every successful attach by a tool

After the first devcontainer up, the file held the five container commands in that order. I then stopped the container with Docker and ran devcontainer up again.

onCreateCommand
updateContentCommand
postCreateCommand
postStartCommand
postAttachCommand
postStartCommand
postAttachCommand

Only the last two ran again. So put one-time setup, such as installing project dependencies, in postCreateCommand. Put things that must happen on every start, such as starting a background service, in postStartCommand.

Building from a Dockerfile

An image is the simplest start. When you need more, point the file at a Dockerfile. GitHub’s documentation says you reference it with the dockerfile property.

{
  "name": "built-from-dockerfile",
  "build": { "dockerfile": "Dockerfile" }
}

In the lab, the Dockerfile started from the same Alpine image and wrote one marker file. After devcontainer up, the marker was present inside the container.

baked into the image at build time

Features, and one that failed on Alpine

Features are reusable units of install code. The Features reference defines a Feature as a folder that stands on its own and holds, at minimum, a devcontainer-feature.json file and an install.sh script to run.

I wrote a tiny local Feature that writes a greeting to a file, and passed the greeting as an option. Per the specification, the install script receives each option as an environment variable. It worked.

hello from a Feature
lockfile written: devcontainer-lock.json

The second line matters for teams. The CLI README says lockfiles are generated by default when running build or up, to pin Feature versions for reproducible builds. Commit that file with the project.

Then I added the GitHub CLI Feature from the official collection to the same Alpine image. The build failed.

./install.sh: line 101: apt-get: command not found
outcome: error

The cause is in the Feature’s install script, which calls apt-get. That tool belongs to Debian and Ubuntu, and the Alpine image does not have it. I did not test the Feature on a Debian image.

This result is about one Feature. It does not show that Features in general fail on Alpine. The local Feature in the previous test installed on the same Alpine image.

The lesson is general. A Feature is a shell script that runs during the image build, so it only works on base images it was written for. Check a Feature’s documentation before you pair it with a small image.

Dev containers and Claude Code

Anthropic’s documentation says Claude Code installs into any dev container through the Claude Code Dev Container Feature. The documented entry for the features block is this.

"ghcr.io/anthropics/devcontainer-features/claude-code:1.0": {}

The same page explains the benefit: commands Claude runs execute inside the container rather than on the host machine, while edits to your project files appear in your local repository as you work.

It also carries a warning that I want to repeat. When Claude Code is executed with --dangerously-skip-permissions, dev containers do not prevent a malicious project from exfiltrating anything accessible inside the container.

So a dev container narrows what a coding agent can reach. It is not a guarantee. Anthropic’s page advises against mounting host secrets such as ~/.ssh or cloud credential files into the container.

Our Claude Code guide covers the permission modes.

Common problems and where to look

SymptomLikely causeWhat to do
A Feature fails with apt-get: command not foundThe Feature’s script expects Debian or Ubuntu and the image is AlpineUse a Debian or Ubuntu based image, or a Feature written for your image
A port in forwardPorts is not reachable from the hostNo editor or tool is attached to do the forwardingConnect with a supporting editor to use port forwarding, or publish the port with appPort. For a published port, make sure the application listens on an address reachable through the container’s network interface, not only on the container’s loopback address
A config change has no effectThe container was built from the old fileRebuild the container
Setup runs again on every startThe command is in postStartCommandMove one-time work to postCreateCommand
An extension misbehaves on AlpineVS Code’s documentation warns that extensions with native code built against glibc can fail on AlpineTry a Debian or Ubuntu based image

The first, second and fourth rows come from my lab. The third and fifth come from the documentation.

Where a dev container fits on your machine

A dev container holds project tools. It does not replace the host setup you still need, such as Docker, an editor and Git. On a Mac, our Homebrew guide for macOS developers covers installing those.

The two approaches work well together. Keep the host small and stable, and move per-project runtimes and command line tools into the container, where a teammate gets the same versions.

Limits of this lab

  • It ran on one Linux machine with one CLI version and one Docker version. Other versions may behave differently.
  • It used tiny commands that write files. It did not install a real language toolchain or measure performance.
  • It tested the CLI, not the VS Code extension. The extension adds behavior, including port forwarding, that the lab could not show.
  • The Alpine failure was seen with one Feature, whose script needs apt-get. It does not show that Features in general fail on Alpine.
  • The forwardPorts result applies to the CLI with no editor attached. VS Code’s own forwarding was not tested.
  • Download times and first-run times were not measured.

How the evidence is checked

The evidence package is a download: dev containers evidence package. It holds the lab script, the six project folders, the transcript, a ledger of 9 records and a checker script.

The lab script is lab/run_lab.sh. To repeat the lab, you need a Linux machine with Docker running, Node.js, Python 3 and the Dev Container CLI. I used Docker 29.10.0, Node.js 22.23.5 and CLI 0.90.0.

  1. Install the CLI with npm install -g @devcontainers/cli, the command its README gives.
  2. Extract the evidence package. The lab folder holds run_lab.sh, safety_tests.sh, env.sh and six project folders: demo, ports, steps, built, feat-local and feat-apt.
  3. Open env.sh and change its PATH line to point at your own devcontainer and node programs. Both scripts read that file. Delete the line if both programs are already on your path.
  4. Run bash run_lab.sh as a user who is allowed to use Docker. The script copies the projects into a new private folder under /tmp and works there.
  5. The run prints 13 numbered test sections after a version check. A complete run exits with status 0, removes the containers it created and deletes its private folder. It leaves the images in place on purpose.
  6. If a test does not give its expected result, the script reports LAB FAILED and exits with status 1, provided cleanup succeeds. It keeps the private folder and prints its path.
  7. If cleanup also fails, or fails after a complete run, it reports CLEANUP FAILED with the container IDs and exits with status 3.
  8. If the CLI returns without a container ID that passes the checks, the script prints POSSIBLE LEFTOVER for that folder and removes nothing there.
  9. If you stop a run, it reports LAB STOPPED and exits with status 130. If devcontainer up had not yet returned at that moment, it also prints POSSIBLE LEFTOVER and leaves that container for you to inspect.
  10. To check for leftovers, run docker ps -a --filter label=devcontainer.local_folder --format '{{.ID}} {{.Label "devcontainer.local_folder"}}'. Look for lines whose folder starts with /tmp/dclab. and remove only those IDs.
  11. Run bash safety_tests.sh to repeat the six safety tests. Each prints RESULT: pass or an ERROR line.

Other versions may print different output. A first run also downloads the base image, so it takes longer than the timings in my transcript.

The checker is dev_containers_evidence.py. It validates the saved evidence and does not rerun the Docker tests.

It verifies the 51 selected passages against the saved pages. It confirms that 32 transcript lines quoted in this article are whole lines of the saved transcript.

It also checks 15 numerical statements in this article against a list of 12 figures, and pairs 23 of the article’s assertions with source passages. It cannot judge whether a passage justifies a sentence.

The checker does not start Docker and cannot repeat the lab. For the lab, it only proves that the transcript is intact and quoted accurately. The saved pages are not redistributed. A second script downloads them again.

Circuit Times prepared this package with AI assistance. It is not an independent audit.

Frequently asked questions

What is the difference between dev containers and Docker?

Docker is the engine that builds containers and runs them. A dev container is a container set up for development from a devcontainer.json file, which adds the project mount, the user, lifecycle commands and editor settings on top of Docker.

How do I install the Dev Containers extension in VS Code?

In VS Code’s Extensions view, look up Dev Containers and pick the one Microsoft publishes. Its identifier is ms-vscode-remote.remote-containers. You also need Docker, which the extension uses to build and run containers.

What does Dev Containers: Reopen in Container do?

It reads the project’s devcontainer.json, creates or starts the container, and reconnects VS Code to it. From then on the terminal, the extensions and your tools run inside the container.

Can I use dev containers without VS Code?

Yes. The Dev Container CLI reads the same file, and in my lab devcontainer up started a working container on its own. The specification’s site also lists other editors and GitHub Codespaces as supporting tools.

How do I use dev containers in Cursor?

I did not test Cursor, and the specification’s supporting tools page did not list it on the day I saved it. So I cannot give verified Cursor steps, and I will not guess at menu names.

Two things from this guide still apply. A devcontainer.json file is not tied to one editor, and the CLI started my container with no editor attached.

Check Cursor’s own documentation for its current dev container support. If it falls short for your project, you can start the container with the CLI and work in it from a terminal.

Can I run Claude Code in a dev container?

Yes. Anthropic documents a Dev Container Feature that installs Claude Code into a dev container. Read its warning about skipped permissions first, and avoid mounting host secrets into the container.

Is the Dev Container CLI the same as the devcontainer command in VS Code?

They are related. According to the specification’s site, the VS Code extension ships its own version of the CLI, with an extra command that opens a dev container in VS Code from a terminal.

All 14 source pages are linked in the Sources list below.

Up nextHomebrew guide for macOS developersSet up the rest of a developer machine with one package manager.

From circuittimes.com/cloud-dev/dev-containers/

Was this guide helpful?

Keep going

More in Developer Tools

See all

The briefing, without the noise.

The stories that matter in technology, every weekday morning.

Free. Unsubscribe in one click.