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
Alternatively, install `@devcontainer/cli` manually in your base image:
51
+
Alternatively, you can install `@devcontainer/cli` manually in your base image:
52
52
53
53
```shell
54
54
RUN npm install -g @devcontainers/cli
55
55
```
56
56
57
+
## Configure the Agent for Docker Support
58
+
59
+
Your Coder agent needs proper configuration to support Docker and dev containers:
60
+
61
+
```terraform
62
+
resource "coder_agent" "main" {
63
+
os = "linux"
64
+
arch = "amd64"
65
+
66
+
# Ensure Docker starts before the agent considers the workspace ready
67
+
startup_script_behavior = "blocking"
68
+
startup_script = "sudo service docker start"
69
+
70
+
# Properly shut down Docker when the workspace stops
71
+
shutdown_script = "sudo service docker stop"
72
+
}
73
+
```
74
+
75
+
The `blocking` behavior ensures Docker is fully started before the workspace is considered ready, which is critical for dev containers to function correctly.
76
+
57
77
## Define the Dev Container Resource
58
78
59
-
If you don't use the [`git-clone`](#clone-the-repository) module, point the resource at the folder that contains `devcontainer.json`:
79
+
Use the git-clone module to provide repository access and define the dev container:
workspace_folder = module.git-clone[0].repo_dir # Points to the cloned repository
94
+
}
95
+
```
96
+
97
+
The `repo_dir` output from the git-clone module provides the path to the cloned repository.
98
+
99
+
### If you're not using the git-clone module
100
+
101
+
If you need to point to a pre-existing directory or have another way of provisioning repositories, specify the directory that contains the dev container configuration:
60
102
61
103
```terraform
62
104
resource "coder_devcontainer" "my-repository" {
63
-
count = data.coder_workspace.me.start_count
64
-
agent_id = coder_agent.main.id
65
-
workspace_folder = "/home/coder/project" # or /home/coder/project/.devcontainer
105
+
count = data.coder_workspace.me.start_count
106
+
agent_id = coder_agent.main.id
107
+
workspace_folder = "/home/coder/project" # Path to a folder with devcontainer.json
66
108
}
67
109
```
68
110
69
111
> [!NOTE]
70
-
> The `workspace_folder` attribute must specify the location of the dev
71
-
> container's workspace and should point to a valid project folder containing a
72
-
> `devcontainer.json` file.
112
+
> The `workspace_folder` attribute must specify the location of the dev container's workspace and should point to a
113
+
> valid project directory that contains a `devcontainer.json` file or `.devcontainer` directory.
114
+
115
+
## Create the Docker Container Resource
116
+
117
+
Configure the Docker container to run the Coder agent and enable Docker-in-Docker capabilities required for dev containers.
118
+
119
+
This example uses the `sysbox-runc` runtime for secure container isolation.
120
+
If sysbox isn't available in your environment, consult [Docker in workspaces](./docker-in-workspaces.md) for alternatives.
121
+
122
+
```terraform
123
+
resource "docker_container" "workspace" {
124
+
count = data.coder_workspace.me.start_count
125
+
126
+
# Base image - this example uses one with npm pre-installed
127
+
image = "codercom/enterprise-node:ubuntu"
128
+
129
+
# Create a unique container name to avoid conflicts
130
+
name = "coder-${data.coder_workspace_owner.me.name}-${lower(data.coder_workspace.me.name)}"
0 commit comments