Skip to content

Commit 7d412c2

Browse files
authored
feat(examples/templates): add docker-devcontainer template and rename envbuilder template (#18741)
This change adds a new `docker-devcontainer` template which allows you to provision a workspace running in Docker, that also creates workspaces via Docker running inside (DinD). - **chore(examples/templates): rename `docker-devcontainer` to `docker-envbuilder`** - **feat(examples/templates): add `docker-devcontainer` example template**
1 parent 8b6d70b commit 7d412c2

File tree

9 files changed

+779
-305
lines changed

9 files changed

+779
-305
lines changed

cli/testdata/coder_templates_init_--help.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ USAGE:
66
Get started with a templated template.
77

88
OPTIONS:
9-
--id aws-devcontainer|aws-linux|aws-windows|azure-linux|digitalocean-linux|docker|docker-devcontainer|gcp-devcontainer|gcp-linux|gcp-vm-container|gcp-windows|kubernetes|kubernetes-devcontainer|nomad-docker|scratch
9+
--id aws-devcontainer|aws-linux|aws-windows|azure-linux|digitalocean-linux|docker|docker-devcontainer|docker-envbuilder|gcp-devcontainer|gcp-linux|gcp-vm-container|gcp-windows|kubernetes|kubernetes-devcontainer|nomad-docker|scratch
1010
Specify a given example template by ID.
1111

1212
———

docs/reference/cli/templates_init.md

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/examples.gen.json

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,29 @@
8383
{
8484
"id": "docker-devcontainer",
8585
"url": "",
86-
"name": "Docker (Devcontainer)",
86+
"name": "Docker-in-Docker Dev Containers",
87+
"description": "Provision Docker containers as Coder workspaces running Dev Containers via Docker-in-Docker.",
88+
"icon": "/icon/docker.png",
89+
"tags": [
90+
"docker",
91+
"container",
92+
"devcontainer"
93+
],
94+
"markdown": "\n# Remote Development on Dev Containers\n\nProvision Docker containers as [Coder workspaces](https://coder.com/docs/workspaces) running [Dev Containers](https://code.visualstudio.com/docs/devcontainers/containers) via Docker-in-Docker.\n\n\u003c!-- TODO: Add screenshot --\u003e\n\n## Prerequisites\n\n### Infrastructure\n\nThe VM you run Coder on must have a running Docker socket and the `coder` user must be added to the Docker group:\n\n```sh\n# Add coder user to Docker group\nsudo adduser coder docker\n\n# Restart Coder server\nsudo systemctl restart coder\n\n# Test Docker\nsudo -u coder docker ps\n```\n\n## Architecture\n\nThis example uses the `codercom/enterprise-node:ubuntu` Docker image as a base image for the workspace. It includes necessary tools like Docker and Node.js, which are required for running Dev Containers via the `@devcontainers/cli` tool.\n\nThis template provisions the following resources:\n\n- Docker image (built by Docker socket and kept locally)\n- Docker container (ephemeral)\n- Docker volume (persistent on `/home/coder`)\n- Docker volume (persistent on `/var/lib/docker`)\n\nThis means, when the workspace restarts, any tools or files outside of the home directory or docker library are not persisted.\n\nFor devcontainers running inside the workspace, data persistence is dependent on each projects `devcontainer.json` configuration.\n\n\u003e **Note**\n\u003e This template is designed to be a starting point! Edit the Terraform to extend the template to support your use case.\n"
95+
},
96+
{
97+
"id": "docker-envbuilder",
98+
"url": "",
99+
"name": "Docker (Envbuilder)",
87100
"description": "Provision envbuilder containers as Coder workspaces",
88101
"icon": "/icon/docker.png",
89102
"tags": [
90103
"container",
91104
"docker",
92-
"devcontainer"
105+
"devcontainer",
106+
"envbuilder"
93107
],
94-
"markdown": "\n# Remote Development on Docker Containers (with Devcontainers)\n\nProvision Devcontainers as [Coder workspaces](https://coder.com/docs/workspaces) in Docker with this example template.\n\n## Prerequisites\n\n### Infrastructure\n\nCoder must have access to a running Docker socket, and the `coder` user must be a member of the `docker` group:\n\n```shell\n# Add coder user to Docker group\nsudo usermod -aG docker coder\n\n# Restart Coder server\nsudo systemctl restart coder\n\n# Test Docker\nsudo -u coder docker ps\n```\n\n## Architecture\n\nCoder supports Devcontainers via [envbuilder](https://github.com/coder/envbuilder), an open source project. Read more about this in [Coder's documentation](https://coder.com/docs/templates/dev-containers).\n\nThis template provisions the following resources:\n\n- Envbuilder cached image (conditional, persistent) using [`terraform-provider-envbuilder`](https://github.com/coder/terraform-provider-envbuilder)\n- Docker image (persistent) using [`envbuilder`](https://github.com/coder/envbuilder)\n- Docker container (ephemeral)\n- Docker volume (persistent on `/workspaces`)\n\nThe Git repository is cloned inside the `/workspaces` volume if not present.\nAny local changes to the Devcontainer files inside the volume will be applied when you restart the workspace.\nKeep in mind that any tools or files outside of `/workspaces` or not added as part of the Devcontainer specification are not persisted.\nEdit the `devcontainer.json` instead!\n\n\u003e **Note**\n\u003e This template is designed to be a starting point! Edit the Terraform to extend the template to support your use case.\n\n## Docker-in-Docker\n\nSee the [Envbuilder documentation](https://github.com/coder/envbuilder/blob/main/docs/docker.md) for information on running Docker containers inside a devcontainer built by Envbuilder.\n\n## Caching\n\nTo speed up your builds, you can use a container registry as a cache.\nWhen creating the template, set the parameter `cache_repo` to a valid Docker repository.\n\nFor example, you can run a local registry:\n\n```shell\ndocker run --detach \\\n --volume registry-cache:/var/lib/registry \\\n --publish 5000:5000 \\\n --name registry-cache \\\n --net=host \\\n registry:2\n```\n\nThen, when creating the template, enter `localhost:5000/devcontainer-cache` for the parameter `cache_repo`.\n\nSee the [Envbuilder Terraform Provider Examples](https://github.com/coder/terraform-provider-envbuilder/blob/main/examples/resources/envbuilder_cached_image/envbuilder_cached_image_resource.tf/) for a more complete example of how the provider works.\n\n\u003e [!NOTE]\n\u003e We recommend using a registry cache with authentication enabled.\n\u003e To allow Envbuilder to authenticate with the registry cache, specify the variable `cache_repo_docker_config_path`\n\u003e with the path to a Docker config `.json` on disk containing valid credentials for the registry.\n"
108+
"markdown": "\n# Remote Development on Docker Containers (with Envbuilder)\n\nProvision Envbuilder containers based on `devcontainer.json` as [Coder workspaces](https://coder.com/docs/workspaces) in Docker with this example template.\n\n## Prerequisites\n\n### Infrastructure\n\nCoder must have access to a running Docker socket, and the `coder` user must be a member of the `docker` group:\n\n```shell\n# Add coder user to Docker group\nsudo usermod -aG docker coder\n\n# Restart Coder server\nsudo systemctl restart coder\n\n# Test Docker\nsudo -u coder docker ps\n```\n\n## Architecture\n\nCoder supports Envbuilder containers based on `devcontainer.json` via [envbuilder](https://github.com/coder/envbuilder), an open source project. Read more about this in [Coder's documentation](https://coder.com/docs/templates/dev-containers).\n\nThis template provisions the following resources:\n\n- Envbuilder cached image (conditional, persistent) using [`terraform-provider-envbuilder`](https://github.com/coder/terraform-provider-envbuilder)\n- Docker image (persistent) using [`envbuilder`](https://github.com/coder/envbuilder)\n- Docker container (ephemeral)\n- Docker volume (persistent on `/workspaces`)\n\nThe Git repository is cloned inside the `/workspaces` volume if not present.\nAny local changes to the Devcontainer files inside the volume will be applied when you restart the workspace.\nKeep in mind that any tools or files outside of `/workspaces` or not added as part of the Devcontainer specification are not persisted.\nEdit the `devcontainer.json` instead!\n\n\u003e **Note**\n\u003e This template is designed to be a starting point! Edit the Terraform to extend the template to support your use case.\n\n## Docker-in-Docker\n\nSee the [Envbuilder documentation](https://github.com/coder/envbuilder/blob/main/docs/docker.md) for information on running Docker containers inside an Envbuilder container.\n\n## Caching\n\nTo speed up your builds, you can use a container registry as a cache.\nWhen creating the template, set the parameter `cache_repo` to a valid Docker repository.\n\nFor example, you can run a local registry:\n\n```shell\ndocker run --detach \\\n --volume registry-cache:/var/lib/registry \\\n --publish 5000:5000 \\\n --name registry-cache \\\n --net=host \\\n registry:2\n```\n\nThen, when creating the template, enter `localhost:5000/envbuilder-cache` for the parameter `cache_repo`.\n\nSee the [Envbuilder Terraform Provider Examples](https://github.com/coder/terraform-provider-envbuilder/blob/main/examples/resources/envbuilder_cached_image/envbuilder_cached_image_resource.tf/) for a more complete example of how the provider works.\n\n\u003e [!NOTE]\n\u003e We recommend using a registry cache with authentication enabled.\n\u003e To allow Envbuilder to authenticate with the registry cache, specify the variable `cache_repo_docker_config_path`\n\u003e with the path to a Docker config `.json` on disk containing valid credentials for the registry.\n"
95109
},
96110
{
97111
"id": "gcp-devcontainer",

examples/examples.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var (
3131
//go:embed templates/digitalocean-linux
3232
//go:embed templates/docker
3333
//go:embed templates/docker-devcontainer
34+
//go:embed templates/docker-envbuilder
3435
//go:embed templates/gcp-devcontainer
3536
//go:embed templates/gcp-linux
3637
//go:embed templates/gcp-vm-container
Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
---
2-
display_name: Docker (Devcontainer)
3-
description: Provision envbuilder containers as Coder workspaces
2+
display_name: Docker-in-Docker Dev Containers
3+
description: Provision Docker containers as Coder workspaces running Dev Containers via Docker-in-Docker.
44
icon: ../../../site/static/icon/docker.png
55
maintainer_github: coder
66
verified: true
7-
tags: [container, docker, devcontainer]
7+
tags: [docker, container, devcontainer]
88
---
99

10-
# Remote Development on Docker Containers (with Devcontainers)
10+
# Remote Development on Dev Containers
1111

12-
Provision Devcontainers as [Coder workspaces](https://coder.com/docs/workspaces) in Docker with this example template.
12+
Provision Docker containers as [Coder workspaces](https://coder.com/docs/workspaces) running [Dev Containers](https://code.visualstudio.com/docs/devcontainers/containers) via Docker-in-Docker.
13+
14+
<!-- TODO: Add screenshot -->
1315

1416
## Prerequisites
1517

1618
### Infrastructure
1719

18-
Coder must have access to a running Docker socket, and the `coder` user must be a member of the `docker` group:
20+
The VM you run Coder on must have a running Docker socket and the `coder` user must be added to the Docker group:
1921

20-
```shell
22+
```sh
2123
# Add coder user to Docker group
22-
sudo usermod -aG docker coder
24+
sudo adduser coder docker
2325

2426
# Restart Coder server
2527
sudo systemctl restart coder
@@ -30,48 +32,18 @@ sudo -u coder docker ps
3032

3133
## Architecture
3234

33-
Coder supports Devcontainers via [envbuilder](https://github.com/coder/envbuilder), an open source project. Read more about this in [Coder's documentation](https://coder.com/docs/templates/dev-containers).
35+
This example uses the `codercom/enterprise-node:ubuntu` Docker image as a base image for the workspace. It includes necessary tools like Docker and Node.js, which are required for running Dev Containers via the `@devcontainers/cli` tool.
3436

3537
This template provisions the following resources:
3638

37-
- Envbuilder cached image (conditional, persistent) using [`terraform-provider-envbuilder`](https://github.com/coder/terraform-provider-envbuilder)
38-
- Docker image (persistent) using [`envbuilder`](https://github.com/coder/envbuilder)
39+
- Docker image (built by Docker socket and kept locally)
3940
- Docker container (ephemeral)
40-
- Docker volume (persistent on `/workspaces`)
41+
- Docker volume (persistent on `/home/coder`)
42+
- Docker volume (persistent on `/var/lib/docker`)
43+
44+
This means, when the workspace restarts, any tools or files outside of the home directory or docker library are not persisted.
4145

42-
The Git repository is cloned inside the `/workspaces` volume if not present.
43-
Any local changes to the Devcontainer files inside the volume will be applied when you restart the workspace.
44-
Keep in mind that any tools or files outside of `/workspaces` or not added as part of the Devcontainer specification are not persisted.
45-
Edit the `devcontainer.json` instead!
46+
For devcontainers running inside the workspace, data persistence is dependent on each projects `devcontainer.json` configuration.
4647

4748
> **Note**
4849
> This template is designed to be a starting point! Edit the Terraform to extend the template to support your use case.
49-
50-
## Docker-in-Docker
51-
52-
See the [Envbuilder documentation](https://github.com/coder/envbuilder/blob/main/docs/docker.md) for information on running Docker containers inside a devcontainer built by Envbuilder.
53-
54-
## Caching
55-
56-
To speed up your builds, you can use a container registry as a cache.
57-
When creating the template, set the parameter `cache_repo` to a valid Docker repository.
58-
59-
For example, you can run a local registry:
60-
61-
```shell
62-
docker run --detach \
63-
--volume registry-cache:/var/lib/registry \
64-
--publish 5000:5000 \
65-
--name registry-cache \
66-
--net=host \
67-
registry:2
68-
```
69-
70-
Then, when creating the template, enter `localhost:5000/devcontainer-cache` for the parameter `cache_repo`.
71-
72-
See the [Envbuilder Terraform Provider Examples](https://github.com/coder/terraform-provider-envbuilder/blob/main/examples/resources/envbuilder_cached_image/envbuilder_cached_image_resource.tf/) for a more complete example of how the provider works.
73-
74-
> [!NOTE]
75-
> We recommend using a registry cache with authentication enabled.
76-
> To allow Envbuilder to authenticate with the registry cache, specify the variable `cache_repo_docker_config_path`
77-
> with the path to a Docker config `.json` on disk containing valid credentials for the registry.

0 commit comments

Comments
 (0)