#rootless Docker not found

1 messages · Page 1 of 1 (latest)

subtle sigil
#

Running testcontainers in Go fails with the following error: panic: rootless Docker not found. I'm trying to run Postgres container

subtle sigil
#

in Testcontainers code the error is returned because:
/ rootlessDockerSocketPath returns if the path to the rootless Docker socket exists.
// The rootless socket path is determined by the following order:
//
// 1. XDG_RUNTIME_DIR environment variable.
// 2. ~/.docker/run/docker.sock file.
// 3. ~/.docker/desktop/docker.sock file.
// 4. /run/user/${uid}/docker.sock file.
// 5. Else, return ErrRootlessDockerNotFound, wrapping specific errors for each of the above paths.
//
// It should include the Docker socket schema (unix://) in the returned path.

past crystal
# subtle sigil Running testcontainers in Go fails with the following error: panic: rootless Doc...

@subtle sigil that's because testcontainers is very dependend on Docker and it needs a Docker engine to run. There's a testcontainers module in the daggerverse (https://daggerverse.dev/mod/github.com/vito/daggerverse/testcontainers@3509a662fb698b5f0aaf38eaef9a9e0c9dc25d3a) which you can use that will automatically provision the docker engine for you so your tests can run

#

LMK if try that out and you're still having issues 🙏

subtle sigil
#

Tnx @past crystal for your answer, I'm running Dagger using Golang package, not sure how I can reuse the module, not using the CLI

past crystal
# subtle sigil Tnx <@336241811179962368> for your answer, I'm running Dagger using Golang packa...

you can't currently. However, you can check the docker's module code here: https://github.com/vito/daggerverse/blob/3509a662fb698b5f0aaf38eaef9a9e0c9dc25d3a/docker/daemon.go#L25-L51 and borrow that part of the code so you can create the docker daemon service in your code

GitHub

a monorepo of all my Dagger modules. Contribute to vito/daggerverse development by creating an account on GitHub.

subtle sigil
#

Gotcha, I'l give it a try, tnx

#

@past crystal I think I'm missing something, If I have a container with go base image "golang:1.23.3" where the docker:dind comes in?

#

Do I need to create a container based on dockerd?

past crystal
subtle sigil
#

Still missing something

#

How do you think it will solve the errors I'm seeing, a service is a long running container, right?

past crystal
#

that way, testcontainers will find the docker daemon so it can run your tests

subtle sigil
#

By attaching you mean, daisy chaining?

past crystal
#

sorry, I was assuming that you were already familiarized with Dagger services

subtle sigil
#

No worries, I'll give it a try

subtle sigil
#

A small question:
func (b *Builder) Service() *dagger.Service {
var image = "docker:dind"

ctr := b.client.Container().From(image)

// Dagger brings its own pid 1, so set this to avoid a warning.
ctr = ctr.WithEnvVariable("TINI_SUBREAPER", "true")

ctr = ctr.WithExec([]string{
    "dockerd",                   // this appears to be load-bearing
    "--tls=false",               // set a flag explicitly to disable TLS
    "--host=tcp://0.0.0.0:2375", // listen on all interfaces
}, dagger.ContainerWithExecOpts{
    InsecureRootCapabilities: true,
})

ctr = ctr.WithExposedPort(2375)

return ctr.AsService()

}

#

if testPath != "" {
container = container.WithWorkdir("./" + testPath)
}

container = container.WithServiceBinding("docker", docker).
    WithEnvVariable("TESTCONTAINERS_RYUK_DISABLED", "true").
    WithEnvVariable("DOCKER_HOST", "tcp://docker:2375")

_, err := container.WithExec([]string{"go", "test", "./..."}, dagger.ContainerWithExecOpts{
    InsecureRootCapabilities:      true,
    ExperimentalPrivilegedNesting: true,
}).Sync(ctx)
if err != nil {
    return fmt.Errorf("tests failed: %w", err)
}
return nil
#

I'm getting the no command has been set error while I've explicitly set the command

#

Tnx again for helping

past crystal
#

can you try moving the WithExec of the dockerd command inside the AsService call args argument?

#

we've changed the way services work recently in v0.15.x and because you're not using modules, dagger doesn't run in compatibility mode 🙏