Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
DanielleMaywood merged 13 commits intomainfrommafredri/docs-ea-devcontainers
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
13 commits
Select commitHold shift + click to select a range
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
NextNext commit
docs: add early access dev container docs
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
@mafredri
mafredri committedApr 30, 2025
commitde5fbfc98cffafc9117e3971a65421e3ddcec794
3 changes: 3 additions & 0 deletionsdocs/admin/templates/index.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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).
-[Template hardening](./extending-templates/resource-persistence.md#-bulletproofing):
Configure your template to prevent certain resources from being destroyed
(e.g. user disks).
Expand Down
292 changes: 292 additions & 0 deletionsdocs/early-access/devcontainers.md
View file
Open in desktop
Original file line numberDiff line numberDiff 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
- Dev container change detection (coming soon)
- On-demand dev container recreation (coming soon)

## 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

## 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
}
```

### 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",
# ...
]
# ...
}
```

## 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.

### 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.

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.

## Troubleshooting

### Dev Container Not Starting

If your dev container fails to start:

1. Check the workspace logs for detailed error messages
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
19 changes: 19 additions & 0 deletionsdocs/early-access/index.md
View file
Open in desktop
Original file line numberDiff line numberDiff 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>
4 changes: 4 additions & 0 deletionsdocs/user-guides/index.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,4 +7,8 @@ These are intended for end-user flows only. If you are an administrator, please
refer to our docs on configuring [templates](../admin/index.md) or the
[control plane](../admin/index.md).

Check out our [early access features](../early-access/index.md) for upcoming
functionality, including the new
[Dev Containers integration](../early-access/devcontainers.md).

<children></children>
Loading

[8]ページ先頭

©2009-2025 Movatter.jp