Skip to content

docs: add comprehensive dev containers documentation with examples #18582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
718e6f9
remove ea feature status
EdwardAngert Jun 23, 2025
ba7a36c
add advanced dev container doc
EdwardAngert Jun 24, 2025
ef8a4ea
update devcontainers
EdwardAngert Jun 25, 2025
f4db3da
new workspace screenshot
EdwardAngert Jun 25, 2025
df07196
consistent and working examples
EdwardAngert Jun 26, 2025
18998b7
edits; prep advanced doc
EdwardAngert Jun 26, 2025
ddc5893
Merge branch 'main' into dev-container-ga
EdwardAngert Jun 26, 2025
048cf5b
advanced features
EdwardAngert Jun 26, 2025
5dc41a5
better examples
EdwardAngert Jun 26, 2025
be23e85
init user-facing update
EdwardAngert Jun 26, 2025
ec77a25
remove coder_agent_devcontainers_enable requirement
EdwardAngert Jun 27, 2025
06d714c
update features; add personal devcontainer file
EdwardAngert Jun 27, 2025
8f392c0
update troubleshooting
EdwardAngert Jun 27, 2025
2fe5291
add comparison doc; crosslink
EdwardAngert Jun 27, 2025
33d3eed
shorten title
EdwardAngert Jun 27, 2025
747822e
clarify envbuilder doc titles
EdwardAngert Jun 27, 2025
d9f818c
update envbuilder doc with dev container integration consideration
EdwardAngert Jun 27, 2025
c10eb7e
update envbuilder add-devcontainer with dev container integration links
EdwardAngert Jun 27, 2025
3f8970e
envbuilder tweaks
EdwardAngert Jun 27, 2025
0d0a9ba
link fix
EdwardAngert Jun 27, 2025
88e7c0f
tweak to devcontainer.local note
EdwardAngert Jun 27, 2025
8f5e613
ap title case
EdwardAngert Jun 27, 2025
e83d564
leftover ea language
EdwardAngert Jun 27, 2025
03c60bf
update ssh note and example
EdwardAngert Jun 27, 2025
cfcef3c
update example template
EdwardAngert Jun 27, 2025
acdbe4d
Apply suggestions from code review
EdwardAngert Jul 1, 2025
1deae60
Merge branch 'main' into dev-container-ga
EdwardAngert Jul 1, 2025
d3fd3b8
edits from code review
EdwardAngert Jul 1, 2025
6ee9fd4
remove full examples; adjustments from review
EdwardAngert Jul 1, 2025
7b2ba10
Merge branch 'main' into dev-container-ga
EdwardAngert Jul 1, 2025
30372fc
Apply suggestions from code review
EdwardAngert Jul 2, 2025
f7c5272
edit dev-containers-envbuilder
EdwardAngert Jul 2, 2025
9eb367d
edit devcontainers doc
EdwardAngert Jul 2, 2025
abd91a2
changes from code review
EdwardAngert Jul 2, 2025
032edc3
edits
EdwardAngert Jul 2, 2025
1804190
Merge branch 'main' into dev-container-ga
EdwardAngert Jul 2, 2025
67702ae
tested configs; remove untested
EdwardAngert Jul 3, 2025
e8cff18
Merge branch 'main' into dev-container-ga
EdwardAngert Jul 8, 2025
1af39a8
Merge branch 'main' into dev-container-ga
EdwardAngert Jul 8, 2025
11891da
consistency and words
EdwardAngert Jul 9, 2025
0b5cd24
don't encourage envbuilder
EdwardAngert Jul 9, 2025
6485b8f
example edit
EdwardAngert Jul 9, 2025
f1df910
Merge branch 'main' into dev-container-ga
EdwardAngert Jul 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions docs/admin/templates/extending-templates/advanced-dev-containers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Advanced Dev Container Configuration

This page extends the [devcontainers documentation](./devcontainers.md) with patterns for multiple dev containers,
user-controlled startup, repository selection, and infrastructure tuning.

## Run Multiple Dev Containers

Run independent dev containers in the same workspace so each component appears as its own agent.

In this example, there are two: `frontend` and `backend`:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mention here that the names come from the project name (i.e. folder they are cloned into).


```terraform
# Clone each repo
module "git-clone-frontend" {
count = data.coder_workspace.me.start_count
source = "dev.registry.coder.com/modules/git-clone/coder"

agent_id = coder_agent.main.id
url = "https://github.com/your-org/frontend.git"
base_dir = "/home/coder/frontend"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will result in /home/coder/frontend/frontend, we should drop the base_dir for simplicity since it defaults to $HOME.

}

module "git-clone-backend" {
count = data.coder_workspace.me.start_count
source = "dev.registry.coder.com/modules/git-clone/coder"

agent_id = coder_agent.main.id
url = "https://github.com/your-org/backend.git"
base_dir = "/home/coder/backend"
}

# Dev container resources
resource "coder_devcontainer" "frontend" {
count = data.coder_workspace.me.start_count
agent_id = coder_agent.main.id
workspace_folder = "/home/coder/frontend/${module.git-clone-frontend[0].folder_name}"
}

resource "coder_devcontainer" "backend" {
count = data.coder_workspace.me.start_count
agent_id = coder_agent.main.id
workspace_folder = "/home/coder/backend/${module.git-clone-backend[0].folder_name}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
workspace_folder = "/home/coder/backend/${module.git-clone-backend[0].folder_name}"
workspace_folder = module.git-clone-backend[0].repo_dir

Simplification.

}
```

Each dev container appears as a separate agent, so developers can connect to any
component in the workspace.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a better suggestion, but "component" feels a bit off for me and it's feels like we're calling dev containers both dev containers and components.


## Conditional Startup

Use `coder_parameter` booleans to let workspace creators choose which dev containers start automatically,
reducing resource usage for unneeded components:

```terraform
data "coder_parameter" "enable_frontend" {
type = "bool"
name = "Enable frontend container"
Comment on lines +55 to +57
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data "coder_parameter" "enable_frontend" {
type = "bool"
name = "Enable frontend container"
data "coder_parameter" "autostart_frontend" {
type = "bool"
name = "Autostart frontend container"

I suggest alternative terminology here so that we don't accidentally suggest that the exclusion of resource "coder_devcontainer" "frontend" can prevent the devcontainer from showing up in the UI if started manually.

default = true
mutable = true
order = 3
}

resource "coder_devcontainer" "frontend" {
count = data.coder_parameter.enable_frontend.value ? data.coder_workspace.me.start_count : 0
agent_id = coder_agent.main.id
workspace_folder = "/home/coder/frontend/${module.git-clone-frontend[0].folder_name}"
}
```

## Repository-selection Patterns

Prompt users to pick a repository or team at workspace creation time and clone the selected repo(s) automatically into the workspace:

1. Add a parameter to the template:

```terraform
data "coder_parameter" "project" {
name = "project"
display_name = "Choose a project"
type = "string"
default = "https://github.com/coder/coder.git"

option {
name = "coder/coder"
value = "https://github.com/coder/coder.git"
}
option {
name = "Dev Container template"
value = "https://github.com/devcontainers/template-starter.git"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe https://github.com/coder/envbuilder-starter-devcontainer instead? I realize this is just an example, but that specific template-starter is a pretty nonsensical repo for most users. 😄

(Although, we may want to remove envbuilder from the name there.)

}
}
```

1. Change the `git-clone` module to accept the `value` as the `url`:

```terraform
module "git-clone" {
count = data.coder_workspace.me.start_count
source = "dev.registry.coder.com/modules/git-clone/coder"
agent_id = coder_agent.main.id
url = data.coder_parameter.project.value
base_dir = "/home/coder"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Indentation is a bit off on some of these, I recommend sticking to 2 spaces without exception.

}
```

## Troubleshooting

1. Run `docker ps` inside the workspace to ensure Docker is available.
1. Check `/tmp/coder-agent.log` for agent logs.
1. Verify that the workspace image includes Node/npm.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Choose an Approach To Dev Containers

Coder supports two independent ways to run Dev Containers inside a workspace.

Both implement the [Dev Container specification](https://containers.dev/), but they differ in how the container is built,
who controls it, and which runtime requirements exist.

Use this page to decide which path fits your project or platform needs.

## Options at a Glance

| Capability / Trait | Dev Containers integration (CLI-based) | Envbuilder Dev Containers |
|------------------------------------------|------------------------------------------|-------------------------------------------|
| Build engine | `@devcontainers/cli` + Docker | Envbuilder transforms the workspace image |
| Runs separate Docker container | Yes (parent workspace + child container) | No (modifies the parent container) |
| Multiple Dev Containers per workspace | Yes | No |
| Rebuild when `devcontainer.json` changes | Yes (auto-prompt) | Limited (requires full workspace rebuild) |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mafredri what do we think on the wording of auto-prompt here? We don't technically prompt the user they can rebuild, the UI just indicates the dev container is outdated.

Copy link
Member

@mafredri mafredri Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, it feels a bit off. Perhaps "(user initiated, change detection)".

| Docker required in workspace | Yes | No (works in restricted envs) |
| Templates | Standard `devcontainer.json` | Terraform + Envbuilder blocks |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is "Templates" referring to here exactly? Dev Container Templates, Coder Templates?

| Suitable for CI / AI agents | Yes. Deterministic, composable | Less ideal. No isolated container |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean? Why is envbuilder not suitable? It's "just a workspace" in the end and arguably the container is potentially more isolated/locked down compared to a workspace where Docker is allowed to be run.


## How To Migrate From Envbuilder to the Dev Containers Integration

1. Ensure the workspace image can run Docker and has sufficient resources:

```shell
docker ps
```

1. Remove any Envbuilder blocks that reference `coder_dev_envbuilder` from the template.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

1. Add (or keep) a standard `.devcontainer/` folder with `devcontainer.json` in the repository.
1. Follow the [dev containers documentation](./devcontainers.md) for the full list of steps and options.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: It'd be nice to have consistent capitalization. I see some mixed use of Dev Container and dev container, Dev container and devcontainer.

My suggestion: dev container in text, Dev Container in titles, match referencing document case in links and Dev container at the start of a sentence.


At minimum, add the `devcontainers-cli` module and `coder_devcontainer` resource:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also OK to manually install @devcontainers/cli in which case the module wouldn't be needed.


```terraform
module "devcontainers_cli" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
module "devcontainers_cli" {
module "devcontainers-cli" {

Nit: Consistency, as per https://dev.registry.coder.com/modules/coder/devcontainers-cli

source = "dev.registry.coder.com/modules/devcontainers-cli/coder"
agent_id = coder_agent.main.id
}
resource "coder_devcontainer" "project" { # `project` in this example is how users will connect to the dev container: `ssh://project.<workspace>.me.coder`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like project is the name because of the terraform resource name, but I think we should make it more clear it is because of the workspace folder path.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, the comment could be removed. (FYI for Edward, the resource name did play a role in the past, but not in the code that was released in GA.)

count = data.coder_workspace.me.start_count
agent_id = coder_agent.main.id
workspace_folder = "/home/coder/project"
}
```

1. Start a new workspace.
Coder detects and launches the dev container automatically.
1. Verify ports, SSH, and rebuild prompts function as expected.

## Related Reading

- [Dev Containers Integration](./index.md)
- [Troubleshooting Dev Containers](../../../user-guides/devcontainers/troubleshooting-dev-containers.md)
- [Envbuilder on GitHub](https://github.com/coder/envbuilder)
- [Dev Container specification](https://containers.dev/)
Loading
Loading