#Mount docker socket into Dagger engine?

1 messages · Page 1 of 1 (latest)

smoky wasp
#

I am trying to mount my local docker socket to the dagger engine (not the container that dagger spawns like golang:alpine). Is it possible?

brave chasm
#

yep, IIRC there's a guide in the docs for this

#

let me check really quick

smoky wasp
#

I tried to find it in docs but couldn't

brave chasm
#

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)
}
smoky wasp
#

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.

brave chasm
#

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 🤔

smoky wasp
#

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.

brave chasm
#

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

smoky wasp
#

Oh I see. That makes sense.

brave chasm
thorny girder
#

Maybe @steel spoke knows more about this

brave chasm
thorny girder
#

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)

brave chasm
thorny girder
#

unless docker build does a buildkit build of llb.Image("the image") and exports it to itself. Pure speculation, unlikely

steel spoke