Skip to content

Commit 005254d

Browse files
johnstcnmafredri
andauthored
chore(examples): update sample devcontainer templates (#13796)
Updates docker and kubernetes devcontainer templates Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
1 parent 3c2c5ab commit 005254d

File tree

4 files changed

+549
-277
lines changed

4 files changed

+549
-277
lines changed

examples/templates/devcontainer-docker/README.md

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,17 @@ tags: [container, docker, devcontainer]
99

1010
# Remote Development on Docker Containers (with Devcontainers)
1111

12-
Provision Docker containers as [Coder workspaces](https://coder.com/docs/workspaces) with this example template.
13-
14-
<!-- TODO: Add screenshot -->
12+
Provision Devcontainers as [Coder workspaces](https://coder.com/docs/workspaces) in Docker with this example template.
1513

1614
## Prerequisites
1715

1816
### Infrastructure
1917

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

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

2624
# Restart Coder server
2725
sudo systemctl restart coder
@@ -32,19 +30,45 @@ sudo -u coder docker ps
3230

3331
## Architecture
3432

35-
Coder supports devcontainers with [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).
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).
3634

3735
This template provisions the following resources:
3836

39-
- Docker image (built by Docker socket and kept locally)
40-
- Docker container pod (ephemeral)
41-
- Docker volume (persistent on `/home/coder`)
37+
- Docker image (persistent)
38+
- Docker container (ephemeral)
39+
- Docker volume (persistent on `/workspaces`)
4240

43-
This means, when the workspace restarts, any tools or files outside of the home directory are not persisted. To pre-bake tools into the workspace (e.g. `python3`), modify the container image. Alternatively, individual developers can [personalize](https://coder.com/docs/dotfiles) their workspaces with dotfiles.
41+
with [`envbuilder`](https://github.com/coder/envbuilder).
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!
4446

4547
> **Note**
4648
> This template is designed to be a starting point! Edit the Terraform to extend the template to support your use case.
4749
48-
### Editing the image
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`.
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`.
4971

50-
Edit the `Dockerfile` and run `coder templates push` to update workspaces.
72+
> [!NOTE] We recommend using a registry cache with authentication enabled.
73+
> To allow Envbuilder to authenticate with the registry cache, specify the variable `cache_repo_docker_config_path`
74+
> with the path to a Docker config `.json` on disk containing valid credentials for the registry.

0 commit comments

Comments
 (0)