我在 Java/maven 项目中使用 Testcontainer 进行单元和集成测试。测试按预期进行,直到我运行我用来工作的 VPN。 使用 VPN,我可以看到错误消息“Can not connect to Ryuk at localhost:49198”
以下是完整日志:
Connected to the target VM, address: '127.0.0.1:50813', transport: 'socket'
2022-10-03 18:01:49.728 INFO --- [ main] o.t.d.DockerClientProviderStrategy : Loaded org.testcontainers.dockerclient.UnixSocketClientProviderStrategy from ~/.testcontainers.properties, will try it first
2022-10-03 18:01:50.280 INFO --- [ main] o.t.d.DockerClientProviderStrategy : Found Docker environment with local Unix socket (unix:///var/run/docker.sock)
2022-10-03 18:01:50.282 INFO --- [ main] org.testcontainers.DockerClientFactory : Docker host IP address is localhost
2022-10-03 18:01:50.308 INFO --- [ main] org.testcontainers.DockerClientFactory : Connected to docker:
Server Version: 20.10.16
API Version: 1.41
Operating System: Ubuntu 20.04.3 LTS
Total Memory: 15716 MB
2022-10-03 18:01:50.311 INFO --- [ main] o.t.utility.ImageNameSubstitutor : Image name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor')
2022-10-03 18:01:50.926 WARN --- [containers-ryuk] o.testcontainers.utility.ResourceReaper : Can not connect to Ryuk at localhost:49198
java.net.SocketException: Connection reset
at java.base/sun.nio.ch.NioSocketImpl.implRead(NioSocketImpl.java:323)
at java.base/sun.nio.ch.NioSocketImpl.read(NioSocketImpl.java:350)
at java.base/sun.nio.ch.NioSocketImpl$1.read(NioSocketImpl.java:803)
at java.base/java.net.Socket$SocketInputStream.read(Socket.java:966)
at java.base/sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:270)
at java.base/sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:313)
at java.base/sun.nio.cs.StreamDecoder.read(StreamDecoder.java:188)
at java.base/java.io.InputStreamReader.read(InputStreamReader.java:177)
at java.base/java.io.BufferedReader.fill(BufferedReader.java:162)
at java.base/java.io.BufferedReader.readLine(BufferedReader.java:329)
at java.base/java.io.BufferedReader.readLine(BufferedReader.java:396)
at org.testcontainers.utility.ResourceReaper$FilterRegistry.waitForAcknowledgment(ResourceReaper.java:489)
at org.testcontainers.utility.ResourceReaper$FilterRegistry.register(ResourceReaper.java:485)
at org.testcontainers.utility.ResourceReaper.lambda$null$1(ResourceReaper.java:203)
at org.rnorth.ducttape.ratelimits.RateLimiter.doWhenReady(RateLimiter.java:27)
at org.testcontainers.utility.ResourceReaper.lambda$start$2(ResourceReaper.java:185)
at java.base/java.lang.Thread.run(Thread.java:833)
我尝试了多种方法,例如将
TESTCONTAINERS_HOST_OVERRIDE
设置为本地主机,但它不起作用。 (不知道是否考虑到了,这个变量应该在哪里设置?)
我检查了 testcontainers 的 docker 容器,无论是否有 VPN,我没有看到任何区别。
有什么想法吗? 谢谢
问题已解决: VPN 使用与 Docker 相同的 IP 范围,这意味着存在冲突。 我通过创建一个包含另一个范围的 /etc/docker/daemon.json 文件并重新启动 docker 来更改 Docker 的基本 IP 范围(您可以在此处查看:https://medium.com/codebrace/understanding-docker-networks) -并解决与 docker-subnet-ip-range-bfaad092a7ea 的冲突)
我也使用 Ubuntu,但建议的解决方案对我没有帮助。 所以我想分享一个有帮助的现有解决方案。在我根据答案改变我的
/etc/docker/daemon.json
之后https://serverfault.com/a/942176
testcontainers 开始工作,同时 Cisco Anyconnect 也处于活动状态。
我将复制下面答案中的文件内容:
{
"bip": "10.200.0.1/24",
"default-address-pools":[
{"base":"10.201.0.0/16","size":24},
{"base":"10.202.0.0/16","size":24}
]
}