Skip to content

Commit 45677ae

Browse files
committed
Mount /var/lib/docker on a docker volume for DinD
Nested overlay-on-overlay fails when /var/lib/docker lives on the workspace's writable layer (buildkit cache mount: redirect_dir=off, invalid argument). The standard docker:dind image avoids this by declaring VOLUME /var/lib/docker so the path lives on a real filesystem. Resurrect the docker_data volume (per-workspace, named coder-<id>-docker-data) and mount it at /var/lib/docker. Inner dockerd now has a non-overlay filesystem underneath. docker-prune.service still runs on shutdown to keep the volume from accumulating image cache.
1 parent d316619 commit 45677ae

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

main.tf

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,15 +439,27 @@ removed {
439439
}
440440
}
441441

442-
# docker_data volume is no longer managed — the workspace runs Docker-in-
443-
# Docker with /var/lib/docker on the container writable layer (wiped on
444-
# every workspace stop by Coder; docker-prune.service additionally prunes
445-
# on shutdown). Volume is retained to avoid data loss for any workspace
446-
# that still has images/cache in it from the sysbox era.
447-
removed {
448-
from = docker_volume.docker_data
442+
# Per-workspace /var/lib/docker volume. Required for Docker-in-Docker:
443+
# nested overlay-on-overlay fails when /var/lib/docker is on the
444+
# container writable layer, so the inner dockerd needs a real filesystem
445+
# beneath it. docker-prune.service runs `docker system prune -af --volumes`
446+
# on shutdown to keep the volume from accumulating image cache over time.
447+
resource "docker_volume" "docker_data" {
448+
name = "coder-${data.coder_workspace.me.id}-docker-data"
449449
lifecycle {
450-
destroy = false
450+
ignore_changes = all
451+
}
452+
labels {
453+
label = "coder.owner"
454+
value = data.coder_workspace_owner.me.name
455+
}
456+
labels {
457+
label = "coder.owner_id"
458+
value = data.coder_workspace_owner.me.id
459+
}
460+
labels {
461+
label = "coder.workspace_id"
462+
value = data.coder_workspace.me.id
451463
}
452464
}
453465

@@ -549,6 +561,12 @@ resource "docker_container" "workspace" {
549561
read_only = false
550562
}
551563

564+
volumes {
565+
container_path = "/var/lib/docker"
566+
volume_name = docker_volume.docker_data.name
567+
read_only = false
568+
}
569+
552570
# home_persist and shared are NOT terraform-managed — they're owned outside
553571
# this workspace's lifecycle (per-owner and deployment-wide respectively).
554572
# Referencing them by name means workspace destroy won't try to remove them

0 commit comments

Comments
 (0)