I got it working by running a "service" with docker:dind
dockerLibCache := dag.CacheVolume("docker-lib")
dockerCertCache := dag.CacheVolume("docker-certs")
daemon := dag.Container().
From("docker:dind").
WithEnvVariable("DOCKER_TLS_CERTDIR", "/certs").
WithMountedCache("/var/lib/docker", dockerLibCache, dagger.ContainerWithMountedCacheOpts{}).
WithMountedCache("/certs", dockerCertCache, dagger.ContainerWithMountedCacheOpts{}).
WithExposedPort(2376).
AsService(dagger.ContainerAsServiceOpts{
InsecureRootCapabilities: true,
})
and then I can bind my builder container
builder := dag.Container().
From("golang:1.24-alpine").
WithServiceBinding("docker", daemon).
WithMountedCache("/certs", dockerCertCache).
WithEnvVariable("DOCKER_HOST", "tcp://docker:2376").
WithEnvVariable("DOCKER_CERT_PATH", "/certs/client").
WithEnvVariable("DOCKER_TLS_VERIFY", "1").
WithExec(strings.Fields(buildCommand))
The builder ends up running docker build ... and I can get the image via dag.Container().Import(builder.File("image.tar"))
This works, but Im wondering if using a "service" is the right approach.
NOTE: not feasible to rewrite "buildCommand" as a proper dag.Container build.