You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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**
Copy file name to clipboardExpand all lines: examples/examples.gen.json
+17-3Lines changed: 17 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -83,15 +83,29 @@
83
83
{
84
84
"id": "docker-devcontainer",
85
85
"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)",
87
100
"description": "Provision envbuilder containers as Coder workspaces",
88
101
"icon": "/icon/docker.png",
89
102
"tags": [
90
103
"container",
91
104
"docker",
92
-
"devcontainer"
105
+
"devcontainer",
106
+
"envbuilder"
93
107
],
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"
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.
4
4
icon: ../../../site/static/icon/docker.png
5
5
maintainer_github: coder
6
6
verified: true
7
-
tags: [container, docker, devcontainer]
7
+
tags: [docker, container, devcontainer]
8
8
---
9
9
10
-
# Remote Development on Docker Containers (with Devcontainers)
10
+
# Remote Development on Dev Containers
11
11
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 -->
13
15
14
16
## Prerequisites
15
17
16
18
### Infrastructure
17
19
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:
19
21
20
-
```shell
22
+
```sh
21
23
# Add coder user to Docker group
22
-
sudo usermod -aG docker coder
24
+
sudo adduser coder docker
23
25
24
26
# Restart Coder server
25
27
sudo systemctl restart coder
@@ -30,48 +32,18 @@ sudo -u coder docker ps
30
32
31
33
## Architecture
32
34
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.
34
36
35
37
This template provisions the following resources:
36
38
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)
39
40
- 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.
41
45
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.
46
47
47
48
> **Note**
48
49
> 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