Open OHermesJunior opened 2 months ago
Hi, thanks for the response!
TESTCONTAINERS_HOST_OVERRIDE
had the same problem
I am not sure what I should pass to TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE
, as I understand it, it expects a unix socket file path. Not sure I can get it with a TCP socket.
Tested with 127.0.0.1
, tcp://127.0.0.1
, tcp://127.0.0.1:2375
, and got errors like:
tc.testcontainers/ryuk:0.8.1 - Could not start container com.github.dockerjava.api.exception.InternalServerErrorException: Status 500: {"message":"invalid volume specification: 'tcp://127.0.0.1:2375:/var/run/docker.sock:rw'"}
Any idea of what I could use?
To run containers with access to the Docker server we usually run it with --net=host --cap-add=NET_ADMIN --device=/dev/net/tun
I tried modifying RyukContainer with withAccessToHost(true)
and Testcontainers.exposeHostPorts(2375)
, or withNetworkMode("host")
but it didn't work either. I am not very familiar with those APIs, so I might be doing something wrong.
An update on this, I found #5151 which explain a little why ryuk cannot connect to host. I believe this is a strong use case to support, but maybe the decision has been made.
Module
Core
Testcontainers version
1.20.1
Using the latest Testcontainers version?
Yes
Host OS
Linux
Host Arch
amd64
Docker version
What happened?
TestContainers work correctly with a TCP socket as Docker host, which we use in our test environment. But Ryuk never did, so we just disabled it for a few years, assuming it didn't support it.
Reinvestigating the issue now, checking Ryuk's code, it seems like it should support it: https://github.com/testcontainers/moby-ryuk/blob/main/main.go#L120 The docker client gets it's configuration from the environment, and respects DOCKER_HOST.
On the TestContainers side, looks like it simply mounts the UNIX socket, regardless of what the framework itself is using: https://github.com/testcontainers/testcontainers-java/blob/251bca51f4d047d8275b04477273f36de1da7326/core/src/main/java/org/testcontainers/utility/RyukContainer.java#L21-L25
I believe it should be possible to map it to use the TCP socket, and the mismatch between the configuration used by the framework and Ryuk can be considered a bug.
I don't have a POC though, so any ideas on the best approach to do this would be great.
Relevant log output
Additional Information
No response