|
| 1 | +# Docker in Docker |
| 2 | + |
1 | 3 | There are a few ways to run Docker within container-based Coder workspaces. |
2 | 4 |
|
3 | | -## Sysbox runtime (recommended) |
| 5 | +| Method | Description | Limitations | |
| 6 | +| ---------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 7 | +| [Sysbox container runtime](#sysbox-container-runtime) | Install sysbox on your Kubernetes nodes for secure docker-in-docker and systemd-in-docker. Works with GKE, EKS, AKS. | Requires [compatible nodes](https://github.com/nestybox/sysbox#host-requirements). Max of 16 sysbox pods per node. [See all](https://github.com/nestybox/sysbox/blob/master/docs/user-guide/limitations.md) | |
| 8 | +| [Privileged docker sidecar](#privileged-sidecar-container) | Run docker as a privilged sidecar container. | Requires a privileged container. Workspaces can break out to root on the host machine. | |
4 | 9 |
|
5 | | -The [Sysbox](https://github.com/nestybox/sysbox) container runtime allows unprivileged users to run system-level applications, such as Docker, securely from the workspace containers. Sysbox requires a [compatible Linux distribution](https://github.com/nestybox/sysbox/blob/master/docs/distro-compat.md) to implement these security features. |
| 10 | +## Sysbox container runtime |
6 | 11 |
|
7 | | -> Sysbox can also be used to run systemd inside Coder workspaces. See [Systemd in Docker](#systemd-in-docker). |
| 12 | +The [Sysbox](https://github.com/nestybox/sysbox) container runtime allows unprivileged users to run system-level applications, such as Docker, securely from the workspace containers. Sysbox requires a [compatible Linux distribution](https://github.com/nestybox/sysbox/blob/master/docs/distro-compat.md) to implement these security features. Sysbox can also be used to run systemd inside Coder workspaces. See [Systemd in Docker](#systemd-in-docker). |
8 | 13 |
|
9 | 14 | ### Use Sysbox in Docker-based templates |
10 | 15 |
|
@@ -106,7 +111,9 @@ resource "kubernetes_pod" "dev" { |
106 | 111 |
|
107 | 112 | ## Privileged sidecar container |
108 | 113 |
|
109 | | -While less secure, you can attach a [privileged container](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities) to your templates. This may come in handy if your nodes cannot run Sysbox. |
| 114 | +A [privileged container](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities) can be added to your templates to add docker support. This may come in handy if your nodes cannot run Sysbox. |
| 115 | + |
| 116 | +> ⚠️ **Warning**: This is insecure. Workspaces will be able to gain root access to the host machine. |
110 | 117 |
|
111 | 118 | ### Use a privileged sidecar container in Docker-based templates |
112 | 119 |
|
@@ -212,48 +219,6 @@ resource "kubernetes_pod" "main" { |
212 | 219 |
|
213 | 220 | Additionally, [Sysbox](https://github.com/nestybox/sysbox) can be used to give workspaces full `systemd` capabilities. |
214 | 221 |
|
215 | | -### Use systemd in Docker-based templates |
216 | | - |
217 | | -After [installing Sysbox](https://github.com/nestybox/sysbox#installation) on the Coder host, modify your template to use the sysbox-runc runtime and start systemd: |
218 | | - |
219 | | -```hcl |
220 | | -resource "docker_container" "workspace" { |
221 | | - image = "codercom/enterprise-base:ubuntu" |
222 | | - name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}" |
223 | | -
|
224 | | - # Use Sysbox container runtime (required) |
225 | | - runtime = "sysbox-runc" |
226 | | - # Run as root in order to start systemd (required) |
227 | | - user = "0:0" |
228 | | -
|
229 | | - # Start systemd and the Coder agent |
230 | | - command = ["sh", "-c", <<EOF |
231 | | - # Start the Coder agent as the "coder" user |
232 | | - # once systemd has started up |
233 | | - sudo -u coder --preserve-env=CODER_AGENT_TOKEN /bin/bash -- <<-' EOT' & |
234 | | - while [[ ! $(systemctl is-system-running) =~ ^(running|degraded) ]] |
235 | | - do |
236 | | - echo "Waiting for system to start... $(systemctl is-system-running)" |
237 | | - sleep 2 |
238 | | - done |
239 | | - ${coder_agent.main.init_script} |
240 | | - EOT |
241 | | -
|
242 | | - exec /sbin/init |
243 | | - EOF |
244 | | - , |
245 | | - ] |
246 | | - env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"] |
247 | | -} |
248 | | -
|
249 | | -resource "coder_agent" "main" { |
250 | | - arch = data.coder_provisioner.me.arch |
251 | | - os = "linux" |
252 | | -} |
253 | | -``` |
254 | | - |
255 | | -### Use systemd in Kubernetes-based templates |
256 | | - |
257 | 222 | After [installing Sysbox on Kubernetes](https://github.com/nestybox/sysbox/blob/master/docs/user-guide/install-k8s.md), |
258 | 223 | modify your template to use the sysbox-runc RuntimeClass. This requires the Kubernetes Terraform provider version 2.16.0 or greater. |
259 | 224 |
|
|
0 commit comments