-
Notifications
You must be signed in to change notification settings - Fork 929
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
Open
EdwardAngert
wants to merge
36
commits into
main
Choose a base branch
from
dev-container-ga
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+538
−260
Open
Changes from 25 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
718e6f9
remove ea feature status
EdwardAngert ba7a36c
add advanced dev container doc
EdwardAngert ef8a4ea
update devcontainers
EdwardAngert f4db3da
new workspace screenshot
EdwardAngert df07196
consistent and working examples
EdwardAngert 18998b7
edits; prep advanced doc
EdwardAngert ddc5893
Merge branch 'main' into dev-container-ga
EdwardAngert 048cf5b
advanced features
EdwardAngert 5dc41a5
better examples
EdwardAngert be23e85
init user-facing update
EdwardAngert ec77a25
remove coder_agent_devcontainers_enable requirement
EdwardAngert 06d714c
update features; add personal devcontainer file
EdwardAngert 8f392c0
update troubleshooting
EdwardAngert 2fe5291
add comparison doc; crosslink
EdwardAngert 33d3eed
shorten title
EdwardAngert 747822e
clarify envbuilder doc titles
EdwardAngert d9f818c
update envbuilder doc with dev container integration consideration
EdwardAngert c10eb7e
update envbuilder add-devcontainer with dev container integration links
EdwardAngert 3f8970e
envbuilder tweaks
EdwardAngert 0d0a9ba
link fix
EdwardAngert 88e7c0f
tweak to devcontainer.local note
EdwardAngert 8f5e613
ap title case
EdwardAngert e83d564
leftover ea language
EdwardAngert 03c60bf
update ssh note and example
EdwardAngert cfcef3c
update example template
EdwardAngert acdbe4d
Apply suggestions from code review
EdwardAngert 1deae60
Merge branch 'main' into dev-container-ga
EdwardAngert d3fd3b8
edits from code review
EdwardAngert 6ee9fd4
remove full examples; adjustments from review
EdwardAngert 7b2ba10
Merge branch 'main' into dev-container-ga
EdwardAngert 30372fc
Apply suggestions from code review
EdwardAngert f7c5272
edit dev-containers-envbuilder
EdwardAngert 9eb367d
edit devcontainers doc
EdwardAngert abd91a2
changes from code review
EdwardAngert 032edc3
edits
EdwardAngert 1804190
Merge branch 'main' into dev-container-ga
EdwardAngert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
222 changes: 222 additions & 0 deletions
222
docs/admin/templates/extending-templates/advanced-dev-containers.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
# Advanced Dev Container Configuration | ||
|
||
This page extends [devcontainers.md](./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 three: `frontend`, `backend`, and a `database`: | ||
|
||
```terraform | ||
# Clone each repo | ||
module "git_clone_frontend" { | ||
count = data.coder_workspace.me.start_count | ||
source = "registry.coder.com/modules/git-clone/coder" | ||
version = "~> 1.0" | ||
|
||
agent_id = coder_agent.main.id | ||
url = "https://github.com/your-org/frontend.git" | ||
base_dir = "/home/coder/frontend" | ||
} | ||
|
||
module "git_clone_backend" { | ||
count = data.coder_workspace.me.start_count | ||
source = "registry.coder.com/modules/git-clone/coder" | ||
version = "~> 1.0" | ||
|
||
agent_id = coder_agent.main.id | ||
url = "https://github.com/your-org/backend.git" | ||
base_dir = "/home/coder/backend" | ||
} | ||
|
||
module "git_clone_database" { | ||
count = data.coder_workspace.me.start_count | ||
source = "registry.coder.com/modules/git-clone/coder" | ||
version = "~> 1.0" | ||
|
||
agent_id = coder_agent.main.id | ||
url = "https://github.com/your-org/database.git" | ||
base_dir = "/home/coder/database" | ||
} | ||
|
||
# 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}" | ||
depends_on = [module.git_clone_frontend] | ||
} | ||
|
||
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}" | ||
depends_on = [module.git_clone_backend] | ||
} | ||
|
||
resource "coder_devcontainer" "database" { | ||
count = data.coder_workspace.me.start_count | ||
agent_id = coder_agent.main.id | ||
workspace_folder = "/home/coder/database/${module.git_clone_database[0].folder_name}" | ||
depends_on = [module.git_clone_database] | ||
} | ||
``` | ||
|
||
Each dev container appears as a separate agent, so developers can connect to any | ||
component in the workspace. | ||
|
||
## Personal Overrides | ||
|
||
Let developers extend the repo’s `devcontainer.json` with an ignored (by Git) `devcontainer.local.json` file | ||
so they can add personal tools without changing the canonical configuration: | ||
|
||
```jsonc | ||
{ | ||
"extends": "./devcontainer.json", | ||
"features": { | ||
"ghcr.io/devcontainers/features/node": { "version": "20" } | ||
}, | ||
"postStartCommand": "npm i -g tldr" | ||
} | ||
``` | ||
|
||
Add the file name to your project's `.gitignore` or the user's | ||
[global exclude file](https://docs.github.com/en/get-started/git-basics/ignoring-files#configuring-ignored-files-for-all-repositories-on-your-computer). | ||
|
||
## 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" | ||
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}" | ||
depends_on = [module.git_clone_frontend] | ||
} | ||
``` | ||
|
||
## 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: | ||
|
||
### Dropdown selector | ||
|
||
```terraform | ||
data "coder_parameter" "project" { | ||
name = "Project" | ||
description = "Choose a project" | ||
type = "string" | ||
mutable = true | ||
order = 1 | ||
|
||
option { name = "E-commerce FE" value = "https://github.com/org/ecom-fe.git" icon = "/icon/react.svg" } | ||
option { name = "Payment API" value = "https://github.com/org/pay.git" icon = "/icon/nodejs.svg" } | ||
} | ||
|
||
module "git_clone_selected" { | ||
count = data.coder_workspace.me.start_count | ||
source = "registry.coder.com/modules/git-clone/coder" | ||
version = "~> 1.0" | ||
|
||
agent_id = coder_agent.main.id | ||
url = data.coder_parameter.project.value | ||
base_dir = "/home/coder/project" | ||
} | ||
``` | ||
|
||
### Team-based selection | ||
|
||
```terraform | ||
data "coder_parameter" "team" { | ||
name = "Team" | ||
type = "string" | ||
mutable = true | ||
order = 1 | ||
|
||
option { name = "Frontend" value = "frontend" icon = "/icon/react.svg" } | ||
option { name = "Backend" value = "backend" icon = "/icon/nodejs.svg" } | ||
} | ||
|
||
locals { | ||
repos = { | ||
frontend = ["https://github.com/your-org/web.git"] | ||
backend = ["https://github.com/your-org/api.git"] | ||
} | ||
} | ||
|
||
module "git_clone_team" { | ||
count = length(local.repos[data.coder_parameter.team.value]) * data.coder_workspace.me.start_count | ||
source = "registry.coder.com/modules/git-clone/coder" | ||
version = "~> 1.0" | ||
|
||
agent_id = coder_agent.main.id | ||
url = local.repos[data.coder_parameter.team.value][count.index] | ||
base_dir = "/home/coder/${replace(basename(url), \".git\", \"\")}" | ||
} | ||
``` | ||
|
||
## Infrastructure Tuning | ||
|
||
Adjust workspace infrastructure to set memory/CPU limits, attach a custom Docker network, | ||
or add persistent volumes—to improve performance and isolation for dev containers: | ||
|
||
### Resource limits | ||
|
||
```terraform | ||
resource "docker_container" "workspace" { | ||
count = data.coder_workspace.me.start_count | ||
image = "codercom/enterprise-node:ubuntu" | ||
|
||
resources { | ||
memory = 4096 # MiB | ||
cpus = 2 | ||
memory_swap = 8192 | ||
} | ||
} | ||
``` | ||
|
||
### Custom network | ||
|
||
```terraform | ||
resource "docker_network" "dev" { | ||
name = "coder-${data.coder_workspace.me.id}-dev" | ||
} | ||
|
||
resource "docker_container" "workspace" { | ||
networks_advanced { name = docker_network.dev.name } | ||
} | ||
``` | ||
|
||
### Volume caching | ||
|
||
```terraform | ||
resource "docker_volume" "node_modules" { | ||
name = "coder-${data.coder_workspace.me.id}-node-modules" | ||
lifecycle { ignore_changes = all } | ||
} | ||
|
||
resource "docker_container" "workspace" { | ||
volumes { | ||
container_path = "/home/coder/project/node_modules" | ||
volume_name = docker_volume.node_modules.name | ||
} | ||
} | ||
``` | ||
|
||
## Troubleshooting | ||
|
||
1. Run `docker ps` inside the workspace to ensure Docker is available. | ||
1. Check `/tmp/startup.log` for agent logs. | ||
1. Verify the workspace image includes Node/npm or add the `nodejs` module before the `devcontainers_cli` module. |
73 changes: 73 additions & 0 deletions
73
docs/admin/templates/extending-templates/dev-containers-envbuilder.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# 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) | | ||
| Docker required in workspace | Yes | No (works in restricted envs) | | ||
| Admin vs. developer control | Developer decides per repo | Platform admin manages via template | | ||
EdwardAngert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Templates | Standard `devcontainer.json` | Terraform + Envbuilder blocks | | ||
| Suitable for CI / AI agents | Yes. Deterministic, composable | Less ideal. No isolated container | | ||
|
||
## When To Choose the Dev Containers Integration | ||
|
||
Choose the new integration if: | ||
|
||
- Your workspace image can run Docker (DinD, Sysbox, or a mounted Docker socket). | ||
EdwardAngert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- You need multiple Dev Containers (like `frontend`, `backend`, `db`) in a single workspace. | ||
- Developers should own their environment and rebuild on demand. | ||
- You rely on features such as automatic port forwarding, full SSH into containers, or change-detection prompts. | ||
|
||
[Dev Container integration](./devcontainers.md) documentation. | ||
|
||
## When To Choose Envbuilder | ||
|
||
Envbuilder remains a solid choice when: | ||
|
||
- Docker isn’t available or allowed inside the workspace image. | ||
- The platform team wants tight control over container contents via Terraform. | ||
EdwardAngert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- A single layered environment is sufficient (no need for separate sub-containers). | ||
EdwardAngert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- You already have Envbuilder templates in production and they meet current needs. | ||
|
||
[Envbuilder Dev Container](../managing-templates/devcontainers/add-devcontainer.md#envbuilder-terraform-provider) documentation. | ||
|
||
## 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. | ||
1. Add (or keep) a standard `.devcontainer/` folder with `devcontainer.json` in the repository. | ||
1. Add the `devcontainers-cli` module: | ||
|
||
```terraform | ||
module "devcontainers_cli" { | ||
source = "dev.registry.coder.com/modules/devcontainers-cli/coder" | ||
agent_id = coder_agent.main.id | ||
} | ||
``` | ||
|
||
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/) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.