Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 20 additions & 28 deletions test/integration/compose_dind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ import (
// dindFeatureRef is the upstream docker-in-docker feature. Its metadata
// declares the mount this test is about —
// {"source":"dind-var-lib-docker-${devcontainerId}","target":"/var/lib/docker","type":"volume"}
// — alongside privileged and the docker-init.sh entrypoint.
const dindFeatureRef = "ghcr.io/devcontainers/features/docker-in-docker:2"
// — alongside privileged and the docker-init.sh entrypoint (and, since
// v4, a second volume at /var/lib/containerd).
//
// Major version 4 or later: v2 switches a Debian image to
// iptables-legacy unconditionally at install time, and the inner
// dockerd then cannot create its NAT chain on hosts whose kernel no
// longer supports legacy iptables (Ubuntu 26.04, the ubuntu-latest
// runner since 2026-11). v4 chooses nft there.
const dindFeatureRef = "ghcr.io/devcontainers/features/docker-in-docker:4"

// dindBaseImage is a Debian base the feature's install script supports.
const dindBaseImage = "debian:bookworm-slim"
Expand Down Expand Up @@ -82,17 +89,7 @@ services:
out, lsErr := exec.Command("docker", "volume", "ls", "-q",
"--filter", "label=com.docker.compose.volume="+volKey).Output()
vols := strings.Fields(string(out))
t.Cleanup(func() {
_ = eng.Down(context.Background(), wsObj, devcontainer.DownOptions{
Remove: true,
RemoveVolumes: true,
})
// Down does not remove every named volume on every
// backend; remove the feature's volume explicitly.
for _, v := range vols {
_ = exec.Command("docker", "volume", "rm", "-f", v).Run()
}
})
cleanupComposeWorkspace(t, eng, wsObj)
if lsErr != nil || len(vols) != 1 || !strings.HasSuffix(vols[0], "_"+volKey) {
t.Fatalf("project volume for %s = %v (err %v), want exactly one <project>_%s", volKey, vols, lsErr, volKey)
}
Expand All @@ -112,20 +109,7 @@ services:

// dockerd is started in the background by the feature's
// entrypoint; wait for it, then run a container.
deadline := time.Now().Add(2 * time.Minute)
for {
res, err := eng.Exec(ctx, wsObj, devcontainer.ExecOptions{
Cmd: []string{"docker", "info", "--format", "{{.Driver}}"},
})
if err == nil && res.ExitCode == 0 {
t.Logf("inner dockerd storage driver: %s", strings.TrimSpace(res.Stdout))
break
}
if time.Now().After(deadline) {
t.Fatalf("inner dockerd never became ready: err=%v res=%+v", err, res)
}
time.Sleep(2 * time.Second)
}
waitInnerDockerd(t, ctx, eng, wsObj)

res, err := eng.Exec(ctx, wsObj, devcontainer.ExecOptions{
Cmd: []string{"docker", "run", "--rm", "hello-world"},
Expand All @@ -150,10 +134,18 @@ func waitInnerDockerd(t *testing.T, ctx context.Context, eng *devcontainer.Engin
Cmd: []string{"docker", "info", "--format", "{{.Driver}}"},
})
if err == nil && res.ExitCode == 0 {
t.Logf("inner dockerd storage driver: %s", strings.TrimSpace(res.Stdout))
return
}
if time.Now().After(deadline) {
t.Fatalf("inner dockerd never became ready: err=%v res=%+v", err, res)
// The feature's docker-init.sh starts dockerd (and
// containerd) in the background with their output in /tmp;
// without it a failure says only that the socket is absent.
diag, _ := eng.Exec(ctx, ws, devcontainer.ExecOptions{Cmd: []string{"sh", "-c",
"uname -r; update-alternatives --query iptables | grep '^Value'; " +
"echo '--- dockerd.log'; tail -n 40 /tmp/dockerd.log; " +
"echo '--- containerd.log'; tail -n 20 /tmp/containerd.log"}})
t.Fatalf("inner dockerd never became ready: err=%v res=%+v\n%s%s", err, res, diag.Stdout, diag.Stderr)
}
time.Sleep(2 * time.Second)
}
Expand Down
Loading