I have got a container with Jenkins. I am trying to run tests pipeline inside this container. Tests uses Testcontainers. I am struggling with error:
18:36:15.560 [testcontainers-ryuk] WARN org.testcontainers.utility.RyukResourceReaper - Cannot connect to Ryuk at 172.17.0.1:55592
java.net.ConnectException: Connection refused (Connection refused)
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:412)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:255)
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:237)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.base/java.net.Socket.connect(Socket.java:609)
at org.testcontainers.utility.RyukResourceReaper.lambda$null$0(RyukResourceReaper.java:92)
at org.rnorth.ducttape.ratelimits.RateLimiter.doWhenReady(RateLimiter.java:27)
at org.testcontainers.utility.RyukResourceReaper.lambda$maybeStart$1(RyukResourceReaper.java:88)
at java.base/java.lang.Thread.run(Thread.java:829)
Jenkins container was run by command
docker run -v /var/run/docker.sock:/var/run/docker.sock -v jenkins_home:/var/jenkins_home -p 8080:8080 -p 5000:5000 -d --restart always <img>
I've tried to run Jenkins container with --network="host"
but same effect.
When I am running those tests directly on my local machine by mvn clean verify
, tests passed and this error didn't occur.
EDIT:
I've changed network to bridge
(--network="bridge"
) for Jenkins container. In test I used explicite network bridge
:
new GenericContainer("mongodb:1..").withNetworkMode("bridge")...
Ryuk container is created (I can see three containers on my host docker - jenkins, mongo, ryuk) and when I run docker network inspect bridge
I can see three containerers are attatched to it. But when I am trying connect to Ryuk container using gateway
(172.17.0.1
) from Jenkins container using telenet it is NOT possible. But when I am using Ryuk IP (172.17.0.2
) instead of gateway
's IP I can connect. Then I've create other container on my host and tryied to connect to it form Jenkins container via gateway
's IP - could do it.
SOLUTION
Just run Jenkins container with -v /var/run/docker.sock.raw:/var/run/docker.sock
instead of -v /var/run/docker.sock:/var/run/docker.sock
.
Thanks @Kevin Wittek!
CodePudding user response:
As mentioned in one of the comments, this originates from an issue in Testcontainers for Java regarding an upstream change in Docker Desktop (see this issue).
The current workaround for Mac is to mount the raw socket when creating the container:
-v /var/run/docker.sock.raw:/var/run/docker.sock