#rootless Docker not found
1 messages · Page 1 of 1 (latest)
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.
@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 🙏
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
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
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?
no, you need to use the above's Service functionon as a service dependency from your golang's code
Still missing something
How do you think it will solve the errors I'm seeing, a service is a long running container, right?
yes, you need to start a docker service and attach it to your testcontainers golang one
that way, testcontainers will find the docker daemon so it can run your tests
By attaching you mean, daisy chaining?
calling WithServiceBinding in the testcontainers Container
using dagger services basically: https://docs.dagger.io/api/services/
sorry, I was assuming that you were already familiarized with Dagger services
No worries, I'll give it a try
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