#Mount docker socket into Dagger engine?
1 messages · Page 1 of 1 (latest)
I tried to find it in docs but couldn't
hmm couldn't find it as well. Let me send you a quick example
package main
import (
"context"
"fmt"
"os"
"dagger.io/dagger"
)
func main() {
ctx := context.Background()
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
if err != nil {
panic(err)
}
container := client.Container()
socket := client.Host().UnixSocket("/var/run/docker.sock")
container = container.
From("docker:cli").
WithUnixSocket("/var/run/docker.sock", socket).
WithExec([]string{"ash", "-c", `
docker ps
`})
out, err := container.Stdout(ctx)
if err != nil {
panic(err)
}
fmt.Println(out)
}
Hmm, this is what I am doing but is this passing the socket to docker:cli or dagger engine itself? What I'm looking for is to be able to pass the socket directly to the dagger engine so when I do container.From("docker:cli") it should be available in my local machine outside of dagger.
oh, now I see what you mean.. Well.. we don't pass the docker socket to the engine since the engine is unaware of docker. The engine only has a dependency on buildkit.
I'm wondering what your use-case is though 🤔
In CI (Jenkins) we use a DinD image as an ephemeral agent per build. That agent can pre-load a bunch of docker containers (we call them buildpacks) that we use for our build tooling. I am looking for a way to pass through those containers to the dagger engine so that dagger engine doesn't have to pull them.
The advantage being, the agent pod resides in a Kube node and if the image was downloaded before it can re-use it instead of re-downloading.
I see.. well... given how Dagger is designed, the Dagger and Docker engines don't share the OCI image store. So basically even if you send the docker socket to our engine, it won't use the docker images you have in the system since buildkit in Dagger has it's own separate image cache.
Having said that, I'll create an issue to describe this since it's understandable that other users assume this as well
cc @steel spoke @thorny girder
Oh I see. That makes sense.
I've opened an issue here: https://github.com/dagger/dagger/issues/4587
There's no workaround that I'm aware of. Each buildkit instance instance has its own image store. docker build uses its own. docker actually doesn't have access to it either -- the docker build command exports the image from buildkit and imports it back into docker
Maybe @steel spoke knows more about this
I think something else is happening under the hood Andrea. If you do docker pull and then docker build, buildkit won't pull the image from scratch and it doesn't seem like docker is importing the image to buldkit. Seems like magically buildkit and docker use the same image under the hood
Good point. Not aware of how that sorcery works
Definitely running "vanilla buildkitd" as a container doesn't give us that
So there must be something that docker is doing with the built-in buildkit
(e.g we had the same problem in dagger-cue which ran a vanilla buildkit)
yep, this. Somehow seems like dockerd is aware of buildkit's image store and makes the integration seamless for this use-case
unless docker build does a buildkit build of llb.Image("the image") and exports it to itself. Pure speculation, unlikely
might be actually...
Got back on the issue here https://github.com/dagger/dagger/issues/4587#issuecomment-1438845335