testcontainers / testcontainers/testcontainers-java

[Bug]: Remote Docker Host not working

オープン
#8,735 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

type/bug
主要言語
Java
スター
8.7k
フォーク
1.9k
平均マージ
2日 17時間
マージ済み PR(30日)
9

説明

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/php@8.0/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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず DockerClientProviderStrategy と TestcontainersHostPropertyClientProviderStrategy の失敗から始め、次にレポートで言及されている ApacheDockerHttpClientImpl のソケット設定を調査します。提供された .testcontainers.properties と Docker のバージョンを使ってリモートの tcp:// 接続を再現し、動作している Docker CLI の接続と比較します。リモート Docker ホストが検出されて使用可能になり、その設定を対象とするリグレッションテストが含まれていれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
docker, java
領域
devops, testing
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。