3

I'm using Testcontainer on Unit and Integration test in a Java/maven project. Tests are working as expected, until I run the VPN I'm using to work. With the VPN, I can see the error message "Can not connect to Ryuk at localhost:49198"

Here are the complete logs:

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)

I tried multiple things like setting TESTCONTAINERS_HOST_OVERRIDE to localhost but it didn't work. (I'm not sure if it was taken into account, where should I set this variable?)

I inspected the docker container of testcontainers, with or without VPN and I don't see any difference.

Any idea? Thanks

  • Normally when connected to a vpn can not access docker registry. Check whether docker image ryuk in machine? – YJR Oct 03 '22 at 16:41
  • Yes ryuk is already pulled and a docker ps shows it running – Quentin Lerebours Oct 03 '22 at 22:09
  • On which OS are you and what version of Docker are you using? Where did you set `TESTCONTAINERS_HOST_OVERRIDE`? It needs to be an environment variable for the process of executing the tests. In case you are on native Linux, I am not sure if Docker transparently supports VPN, seems to be a Docker Desktop feature: https://docs.docker.com/desktop/networking/ – Kevin Wittek Oct 04 '22 at 11:33
  • I'm using Linux (Ubuntu) and I'm using Docker version 20.10.16, build aa7e414. I was trying to set it from .bashrc but now that I'm setting this in my IDE, which runs the test for me, it's taken into account. However, setting it to localhost, 127.0.0.1, 0.0.0.0, or even 172.17.0.4 (which is the container's hostname) isn't working. I'm checking the doc you sent, thanks – Quentin Lerebours Oct 04 '22 at 12:56

1 Answers1

5

Problem solved: The VPN was using the same IP range as Docker, which implied collisions. I solved by changing Docker's base IP range by creating a /etc/docker/daemon.json file with another range in it and restarting docker (you can check here: https://medium.com/codebrace/understanding-docker-networks-and-resolving-conflict-with-docker-subnet-ip-range-bfaad092a7ea)