Skip to content

[Bug]: Remote Docker Host not working #8735

@MrBuddyCasino

Description

@MrBuddyCasino

Module

Core

Testcontainers version

1.19.8

Using the latest Testcontainers version?

Yes

Host OS

Mac

Host Arch

x86

Docker version

Client:
 Cloud integration: v1.0.35
 Version:           24.0.2
 API version:       1.43
 Go version:        go1.20.4
 Git commit:        cb74dfc
 Built:             Thu May 25 21:51:16 2023
 OS/Arch:           darwin/amd64
 Context:           t1-local

Server:
 Engine:
  Version:          25.0.3
  API version:      1.44 (minimum version 1.24)
  Go version:       go1.21.8
  Git commit:       f417435e5f6216828dec57958c490c4f8bae4f98
  Built:            Wed Mar  6 12:07:44 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.7.10
  GitCommit:        4e1fe7492b9df85914c389d1f15a3ceedbb280ac
 runc:
  Version:          1.1.12
  GitCommit:        51d5e94601ceffbbd85688df1c928ecccbfa4685
 docker-init:
  Version:          0.19.0
  GitCommit:

What happened?

I use a Rancher setup on a windows machine running Rancher in my local network, with the Docker port 2375 exposed via:
docker run -d --restart=always -p 0.0.0.0:2375:2375 -v /var/run/docker.sock:/var/run/docker.sock alpine/socat tcp-listen:2375,fork,reuseaddr unix-connect:/var/run/docker.sock

It works fine on my Mac command-line using a t1-local context pointing to the remote machine tcp://michael-t1.local:2375: the command docker ps lists containers as expected.

In my .testcontainers.properties file, I added:

docker.host = tcp://michael-t1.local:2375
tc.host = tcp://michael-t1.local:2375

This does not seem to work, and I don't understand why.

Further context:

  • Opening http://michael-t1.local:2375/info in my web browser returns the expected JSON.
  • Setting different docker.client.strategy values makes no difference.
  • Setting env DOCKER_HOST=tcp://michael-t1.local:2375 makes no difference.

In com.github.dockerjava.httpclient5.ApacheDockerHttpClientImpl, the socket timeout seems to be set to zero:

       // See https://github.com/docker-java/docker-java/pull/1590#issuecomment-870581289
        connectionManager.setDefaultSocketConfig(
            SocketConfig.copy(SocketConfig.DEFAULT)
                .setSoTimeout(Timeout.ZERO_MILLISECONDS)
                .build()
        );

It is hard to tell whats going on, since the ubershaded dependencies make debugging challenging.

Relevant log output

17:53:44.022 [main] INFO com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.HttpRequestRetryExec -- Recoverable I/O exception (java.net.SocketException) caught when processing request to {}->http://michael-t1.local:2375
17:53:48.130 [main] INFO com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.HttpRequestRetryExec -- Recoverable I/O exception (java.net.SocketException) caught when processing request to {}->http://michael-t1.local:2375
17:53:50.180 [main] INFO org.testcontainers.dockerclient.DockerMachineClientProviderStrategy -- docker-machine executable was not found on PATH ([/usr/local/opt/[email protected]/bin, /Users/michaelboeckling/Documents/Tools/zig, /Users/michaelboeckling/Documents/Projekte/zls/zig-out/bin, /Users/michaelboeckling/Documents/Tools/terraform/, /Users/michaelboeckling/.cargo/bin, /usr/local/bin, /usr/bin, /bin, /usr/sbin, /sbin, /opt/X11/bin, /Library/Apple/usr/bin, /Applications/Wireshark.app/Contents/MacOS])
17:53:50.181 [main] ERROR org.testcontainers.dockerclient.DockerClientProviderStrategy -- Could not find a valid Docker environment. Please check configuration. Attempted configurations were:
	TestcontainersHostPropertyClientProviderStrategy: failed with exception RuntimeException (java.net.SocketException: Connection reset). Root cause SocketException (Connection reset)
	EnvironmentAndSystemPropertyClientProviderStrategy: failed with exception RuntimeException (java.net.SocketException: Connection reset). Root cause SocketException (Connection reset)
	UnixSocketClientProviderStrategy: failed with exception InvalidConfigurationException (Could not find unix domain socket). Root cause NoSuchFileException (/var/run/docker.sock)
	DockerDesktopClientProviderStrategy: failed with exception NullPointerException (Cannot invoke "java.nio.file.Path.toString()" because the return value of "org.testcontainers.dockerclient.DockerDesktopClientProviderStrategy.getSocketPath()" is null)As no valid configuration was found, execution cannot continue.
See https://java.testcontainers.org/on_failure.html for more details.

java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configuration

	at org.testcontainers.dockerclient.DockerClientProviderStrategy.lambda$getFirstValidStrategy$7(DockerClientProviderStrategy.java:277)
	at java.base/java.util.Optional.orElseThrow(Optional.java:403)
	at org.testcontainers.dockerclient.DockerClientProviderStrategy.getFirstValidStrategy(DockerClientProviderStrategy.java:268)
	at org.testcontainers.DockerClientFactory.getOrInitializeStrategy(DockerClientFactory.java:152)
	at org.testcontainers.DockerClientFactory.client(DockerClientFactory.java:194)
	at org.testcontainers.DockerClientFactory$1.getDockerClient(DockerClientFactory.java:106)
	at com.github.dockerjava.api.DockerClientDelegate.authConfig(DockerClientDelegate.java:109)
	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:329)

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions