88 "io"
99 "net"
1010 "net/http"
11- "os"
1211 "path/filepath"
1312 "strings"
1413 "sync"
@@ -21,6 +20,7 @@ import (
2120 "github.com/stretchr/testify/require"
2221
2322 "github.com/testcontainers/testcontainers-go/internal/config"
23+ "github.com/testcontainers/testcontainers-go/internal/core"
2424 "github.com/testcontainers/testcontainers-go/log"
2525 "github.com/testcontainers/testcontainers-go/wait"
2626)
@@ -257,8 +257,31 @@ func requireNewMsgs(t *testing.T, c *TestLogConsumer, existing, want int, hint s
257257 return count
258258}
259259
260+ func isRootlessDockerHost (host string ) bool {
261+ return strings .HasPrefix (host , "unix:///run/user/" )
262+ }
263+
264+ func TestIsRootlessDockerHost (t * testing.T ) {
265+ tests := []struct {
266+ name string
267+ host string
268+ want bool
269+ }{
270+ {name : "rootful socket" , host : "unix:///var/run/docker.sock" },
271+ {name : "rootless socket" , host : "unix:///run/user/1000/docker.sock" , want : true },
272+ {name : "remote Docker host" , host : "tcp://localhost:2375" },
273+ }
274+
275+ for _ , tt := range tests {
276+ t .Run (tt .name , func (t * testing.T ) {
277+ require .Equal (t , tt .want , isRootlessDockerHost (tt .host ))
278+ })
279+ }
280+ }
281+
260282func TestContainerLogWithErrClosed (t * testing.T ) {
261- if os .Getenv ("XDG_RUNTIME_DIR" ) != "" {
283+ ctx := context .Background ()
284+ if dockerHost , err := core .ExtractDockerHost (ctx ); err == nil && isRootlessDockerHost (dockerHost ) {
262285 t .Skip ("Docker-in-Docker does not work with rootless Docker" )
263286 }
264287
@@ -272,8 +295,6 @@ func TestContainerLogWithErrClosed(t *testing.T) {
272295 // First spin up a docker-in-docker container, then spin up an inner container within that dind container
273296 // Logs are being read from the inner container via the dind container's tcp port, which can be briefly
274297 // closed to test behaviour in connection-closed situations.
275- ctx := context .Background ()
276-
277298 dind , err := Run (
278299 ctx , "docker:dind" ,
279300 WithExposedPorts ("2375/tcp" ),
0 commit comments