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
# Remote Development on Docker Containers (with Devcontainers)
11
11
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.
15
13
16
14
## Prerequisites
17
15
18
16
### Infrastructure
19
17
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:
21
19
22
-
```sh
20
+
```shell
23
21
# Add coder user to Docker group
24
-
sudo adduser coder docker
22
+
sudo usermod -aG docker coder
25
23
26
24
# Restart Coder server
27
25
sudo systemctl restart coder
@@ -32,19 +30,45 @@ sudo -u coder docker ps
32
30
33
31
## Architecture
34
32
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).
36
34
37
35
This template provisions the following resources:
38
36
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`)
42
40
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!
44
46
45
47
> **Note**
46
48
> This template is designed to be a starting point! Edit the Terraform to extend the template to support your use case.
47
49
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`.
49
71
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