Skip to content

Commit 84d9b74

Browse files
committed
chore(examples): update docker devcontainer template
1 parent 3c2c5ab commit 84d9b74

File tree

2 files changed

+212
-141
lines changed

2 files changed

+212
-141
lines changed

examples/templates/devcontainer-docker/README.md

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@ tags: [container, docker, devcontainer]
1111

1212
Provision Docker containers as [Coder workspaces](https://coder.com/docs/workspaces) with this example template.
1313

14-
<!-- TODO: Add screenshot -->
15-
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
@@ -36,15 +34,38 @@ Coder supports devcontainers with [envbuilder](https://github.com/coder/envbuild
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+
As you might suspect, 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 devcontiner built by Envbuilder.
53+
54+
## Caching
55+
56+
To speed up your builds, you can run a local registry and use it as a cache. For example:
57+
58+
```shell
59+
docker run --detach \
60+
--volume registry-cache:/var/lib/registry \
61+
--publish 5000:5000 \
62+
--name registry-cache \
63+
--net=host \
64+
registry:2
65+
```
66+
67+
Then, when creating a workspace, enter `localhost:5000/devcontainer-cache` for the parameter `cache_repo`.
4968

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

0 commit comments

Comments
 (0)