- Notifications
You must be signed in to change notification settings - Fork929
docs: add early access dev container docs#17613
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
de5fbfc
3a61ec9
2790be9
3df5a33
70e3853
babe9a0
91167b8
f7510d0
81dce70
26d6222
cc07423
466bc9a
ceb514c
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
This change documents the early access dev containers integration andhow to enable it, what features are available and what limitations existat the time of writing.
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -50,6 +50,9 @@ needs of different teams. | ||
create and publish images for use within Coder workspaces & templates. | ||
-[Dev Container support](./managing-templates/devcontainers/index.md): Enable | ||
dev containers to allow teams to bring their own tools into Coder workspaces. | ||
-[Early Access Dev Containers](../../early-access/devcontainers.md): Try our | ||
new direct devcontainers integration (distinct from Envbuilder-based | ||
approach). | ||
mafredri marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
-[Template hardening](./extending-templates/resource-persistence.md#-bulletproofing): | ||
Configure your template to prevent certain resources from being destroyed | ||
(e.g. user disks). | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,292 @@ | ||
# Dev Containers Integration (Early Access) | ||
The dev containers integration is an early access feature that enables seamless | ||
creation and management of dev containers in Coder workspaces. This feature | ||
leverages the [`@devcontainers/cli`](https://github.com/devcontainers/cli) and | ||
[Docker](https://www.docker.com) to provide a streamlined development | ||
experience. | ||
> [!NOTE] | ||
> | ||
> This implementation is different from the existing | ||
> [Envbuilder-based dev containers](../admin/templates/managing-templates/devcontainers/index.md) | ||
> offering. | ||
## Contents | ||
- [Features](#features) | ||
- [Prerequisites](#prerequisites) | ||
- [How It Works](#how-it-works) | ||
- [Template Configuration](#template-configuration) | ||
- [Working with Dev Containers](#working-with-dev-containers) | ||
- [Dev Container Features](#dev-container-features) | ||
- [Limitations during Early Access](#limitations-during-early-access) | ||
- [Comparison with Envbuilder-based Dev Containers](#comparison-with-envbuilder-based-dev-containers) | ||
- [Troubleshooting](#troubleshooting) | ||
- [Next Steps](#next-steps) | ||
## Features | ||
- Automatic dev container detection from repositories | ||
- Seamless dev container startup during workspace initialization | ||
- Integrated IDE experience in dev containers with VS Code | ||
- Direct service access in dev containers | ||
- Native SSH access to dev containers | ||
mafredri marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page.
mafredri marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
- Dev container change detection (coming soon) | ||
- On-demand dev container recreation (coming soon) | ||
mafredri marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
## Prerequisites | ||
- Coder version 2.22.0 or later | ||
- Coder CLI version 2.22.0 or later | ||
- Dev containers integration enabled in your template(s) | ||
- Docker-compatible workspace image in the template(s) | ||
- Appropriate permissions to execute Docker commands | ||
mafredri marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
## How It Works | ||
The dev containers integration utilizes the `devcontainer` command from | ||
[`@devcontainers/cli`](https://github.com/devcontainers/cli) to manage dev | ||
containers within your Coder workspace. This command provides comprehensive | ||
functionality for creating, starting, and managing dev containers. | ||
Dev environments are configured through a standard `devcontainer.json` file, | ||
which allows for extensive customization of your development setup. | ||
When a workspace with the dev containers integration starts: | ||
1. The workspace initializes the Docker environment | ||
2. The integration detects repositories with a `.devcontainer` directory or a | ||
`devcontainer.json` file | ||
3. The integration builds and starts the dev container based on the | ||
configuration | ||
4. Your workspace automatically detects the running dev container | ||
## Template Configuration | ||
To enable the dev containers integration in your template, you need to add | ||
specific configurations as shown below. | ||
### Install the Dev Containers CLI | ||
Use the | ||
[devcontainers-cli](https://registry.coder.com/modules/devcontainers-cli) module | ||
to ensure the `@devcontainers/cli` is installed in your workspace: | ||
```terraform | ||
module "devcontainers-cli" { | ||
count = data.coder_workspace.me.start_count | ||
source = "dev.registry.coder.com/modules/devcontainers-cli/coder" | ||
agent_id = coder_agent.dev.id | ||
} | ||
``` | ||
mafredri marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
### Configure Automatic Dev Container Startup | ||
The | ||
[`coder_devcontainer`](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/devcontainer) | ||
resource automatically starts a dev container in your workspace, ensuring it's | ||
ready when you access the workspace: | ||
```terraform | ||
resource "coder_devcontainer" "my-repository" { | ||
count = data.coder_workspace.me.start_count | ||
agent_id = coder_agent.dev.id | ||
workspace_folder = "/home/coder/my-repository" | ||
} | ||
``` | ||
> [!NOTE] | ||
> | ||
> The `workspace_folder` attribute must specify the location of the dev | ||
> container's workspace and should point to a valid project folder containing a | ||
> `devcontainer.json` file. | ||
> [!TIP] | ||
> | ||
> Consider using the [`git-clone`](https://registry.coder.com/modules/git-clone) | ||
> module to ensure your repository is cloned into the workspace folder and ready | ||
> for automatic startup. | ||
### Complete Template Example | ||
Here's a simplified template example that enables the dev containers | ||
integration: | ||
```terraform | ||
terraform { | ||
required_providers { | ||
coder = { source = "coder/coder" } | ||
docker = { source = "kreuzwerker/docker" } | ||
} | ||
} | ||
provider "coder" {} | ||
data "coder_workspace" "me" {} | ||
data "coder_workspace_owner" "me" {} | ||
resource "coder_agent" "dev" { | ||
arch = "amd64" | ||
os = "linux" | ||
startup_script_behavior = "blocking" | ||
startup_script = "sudo service docker start" | ||
shutdown_script = "sudo service docker stop" | ||
# ... | ||
} | ||
module "devcontainers-cli" { | ||
count = data.coder_workspace.me.start_count | ||
source = "dev.registry.coder.com/modules/devcontainers-cli/coder" | ||
agent_id = coder_agent.dev.id | ||
} | ||
resource "coder_devcontainer" "my-repository" { | ||
count = data.coder_workspace.me.start_count | ||
agent_id = coder_agent.dev.id | ||
workspace_folder = "/home/coder/my-repository" | ||
} | ||
resource "docker_container" "workspace" { | ||
count = data.coder_workspace.me.start_count | ||
image = "codercom/oss-dogfood:latest" | ||
env = [ | ||
"CODER_AGENT_DEVCONTAINERS_ENABLE=true", | ||
mafredri marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
# ... | ||
] | ||
# ... | ||
} | ||
``` | ||
## Working with Dev Containers | ||
### SSH Access | ||
You can SSH into your dev container directly using the Coder CLI: | ||
```console | ||
coder ssh --container keen_dijkstra my-workspace | ||
``` | ||
> [!NOTE] | ||
> | ||
> SSH access is not yet compatible with the `coder config-ssh` command for use | ||
> with OpenSSH. You would need to manually modify your SSH config to include the | ||
> `--container` flag in the `ProxyCommand`. | ||
### Web Terminal Access | ||
Once your workspace and dev container are running, you can use the web terminal | ||
in the Coder interface to execute commands directly inside the dev container. | ||
mafredri marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
### IDE Integration (VS Code) | ||
You can open your dev container directly in VS Code by: | ||
1. Selecting "Open in VS Code Desktop" from the Coder web interface | ||
2. Using the Coder CLI with the container flag: | ||
```console | ||
coder open vscode --container keen_dijkstra my-workspace | ||
``` | ||
While optimized for VS Code, other IDEs with dev containers support may also | ||
work. | ||
### Port Forwarding | ||
During the early access phase, port forwarding is limited to ports defined via | ||
[`appPort`](https://containers.dev/implementors/json_reference/#image-specific) | ||
in your `devcontainer.json` file. | ||
mafredri marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
For example, with this `devcontainer.json` configuration: | ||
```json | ||
{ | ||
"appPort": ["8080:8080", "4000:3000"] | ||
} | ||
``` | ||
You can forward these ports to your local machine using: | ||
```console | ||
coder port-forward my-workspace --tcp 8080,4000 | ||
``` | ||
This forwards port 8080 (local) -> 8080 (agent) -> 8080 (dev container) and port | ||
4000 (local) -> 4000 (agent) -> 3000 (dev container). | ||
## Dev Container Features | ||
You can use standard dev container features in your `devcontainer.json` file. | ||
Coder also maintains a | ||
[repository of features](https://github.com/coder/devcontainer-features) to | ||
enhance your development experience. | ||
Currently available features include: | ||
- [code-server](https://github.com/coder/devcontainer-features/blob/main/src/code-server) | ||
To use the code-server feature, add the following to your `devcontainer.json`: | ||
```json | ||
{ | ||
"features": { | ||
"ghcr.io/coder/devcontainer-features/code-server:1": { | ||
"port": 13337 | ||
} | ||
}, | ||
"appPort": [13337] | ||
} | ||
``` | ||
> [!NOTE] | ||
> | ||
> Remember to include the port in the `appPort` section to ensure proper port | ||
> forwarding. | ||
## Limitations during Early Access | ||
During the early access phase, the dev containers integration has the following | ||
limitations: | ||
- Changes to the `devcontainer.json` file require manual container recreation | ||
- Automatic port forwarding only works for ports specified in `appPort` | ||
- SSH access requires using the `--container` flag | ||
- Some devcontainer features may not work as expected | ||
These limitations will be addressed in future updates as the feature matures. | ||
## Comparison with Envbuilder-based Dev Containers | ||
| Feature | Dev Containers (Early Access) | Envbuilder Dev Containers | | ||
|----------------|----------------------------------------|----------------------------------------------| | ||
| Implementation | Direct `@devcontainers/cli` and Docker | Coder's Envbuilder | | ||
| Target users | Individual developers | Platform teams and administrators | | ||
| Configuration | Standard `devcontainer.json` | Terraform templates with Envbuilder | | ||
| Management | User-controlled | Admin-controlled | | ||
| Requirements | Docker access in workspace | Compatible with more restricted environments | | ||
Choose the appropriate solution based on your team's needs and infrastructure | ||
constraints. | ||
mafredri marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
## Troubleshooting | ||
### Dev Container Not Starting | ||
If your dev container fails to start: | ||
1. Check the workspace logs for detailed error messages | ||
mafredri marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
2. Verify that Docker is running in your workspace | ||
3. Ensure the `devcontainer.json` file is valid | ||
4. Check that the repository has been cloned correctly | ||
5. Verify the resource limits in your workspace are sufficient | ||
## Next Steps | ||
- Explore the [dev container specification](https://containers.dev/) to learn | ||
more about advanced configuration options | ||
- Read about [dev container features](https://containers.dev/features) to | ||
enhance your development environment | ||
- Check the | ||
[VS Code dev containers documentation](https://code.visualstudio.com/docs/devcontainers/containers) | ||
for IDE-specific features |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Early Access Features | ||
This section contains documentation for features that are in early access. These | ||
features are still being developed and may change significantly before general | ||
availability. | ||
Early access features allow you to: | ||
- Test new functionality before it's fully released | ||
- Provide feedback to help shape the future of these features | ||
- Plan ahead for upcoming capabilities in Coder | ||
> [!NOTE] | ||
> | ||
> Early access features are not recommended for production use unless otherwise | ||
> stated. They may have limitations, change without notice, or be removed | ||
> entirely based on user feedback and product direction. | ||
<children></children> |
Uh oh!
There was an error while loading.Please reload this page.