Skip to content

Commit 6bd8f14

Browse files
committed
chore(examples): update docker devcontainer template
1 parent 7c41f95 commit 6bd8f14

File tree

2 files changed

+215
-143
lines changed

2 files changed

+215
-143
lines changed

examples/templates/devcontainer-docker/README.md

Lines changed: 35 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/v2/latest/workspaces) with this example template.
13-
14-
<!-- TODO: Add screenshot -->
12+
Provision Devcontainers as [Coder workspaces](https://coder.com/docs/v2/latest/workspaces) 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,43 @@ 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/v2/latest/templates/dev-containers).
33+
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/v2/latest/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/v2/latest/dotfiles) their workspaces with dotfiles.
41+
This template will fetch a Git repo containing a `devcontainer.json` specified by the `repo` parameter, and builds it
42+
with [`envbuilder`](https://github.com/coder/envbuilder).
43+
The Git repository is cloned inside the `/workspaces` volume if not present.
44+
Any local changes to the Devcontainer files inside the volume will be applied when you restart the workspace.
45+
As you might suspect, any tools or files outside of `/workspaces` or not added as part of the Devcontainer specification are not persisted.
46+
Edit the `devcontainer.json` instead!
4447

4548
> **Note**
4649
> This template is designed to be a starting point! Edit the Terraform to extend the template to support your use case.
4750
48-
### Editing the image
51+
## Docker-in-Docker
52+
53+
See the [Envbuilder documentation](https://github.com/coder/envbuilder/blob/main/docs/docker.md) for information on running Docker containers inside a devcontiner built by Envbuilder.
54+
55+
## Caching
56+
57+
To speed up your builds, you can run a local registry and use it as a cache. For example:
58+
59+
```shell
60+
docker run --detach \
61+
--volume registry-cache:/var/lib/registry \
62+
--publish 5000:5000 \
63+
--name registry-cache \
64+
--net=host \
65+
registry:2
66+
```
67+
68+
Then, when creating a workspace, enter `localhost:5000/devcontainer-cache` for the parameter `cache_repo`.
4969

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

0 commit comments

Comments
 (0)