testcontainers-java icon indicating copy to clipboard operation
testcontainers-java copied to clipboard

Can not connect to Ryuk at localhost:49154

Open dbogdoll opened this issue 3 years ago • 1 comments

Dear all,

I'm running testcontainers on Windows and Linux (WSL2). On both systems I get since some days the following error when I try to use test containers. I'm using Docker Desktop 4.5.1 (74721)

The following logs are from Ubuntu (WSL2):

12:47:43.495 [testcontainers-ryuk] WARN  o.t.utility.ResourceReaper - Can not connect to Ryuk at localhost:49154
java.net.ConnectException: Connection refused: connect

When I run ryuk on its own, I get this

$ docker run quay.io/testcontainers/ryuk
2022/02/25 12:43:56 Starting on port 8080...
panic: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

goroutine 1 [running]:
main.main()
        /go/src/github.com/testcontainers/moby-ryuk/main.go:31 +0xe2e

Here the docker logs of the container when I run it with mvn test:

$ docker logs 4fed1346fccd
2022/02/25 12:52:38 Starting on port 8080...

I get the same output when I run the stuff on windows.

If I look at the line starting with panic:

panic: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

As I'm using Docker Desktop, there is no such pipe, but you could use tcp://0.0.0.0:2375 to connect to docker. But it seems in the past testcontainer had no issue with that. I'm not sure what was updated, so that it is now broken. Is it possible to tell ryuk to use the tcp URL instead of the unix pipe?

Best regards, Dieter

dbogdoll avatar Feb 25 '22 13:02 dbogdoll

When the RYUK container is initiated by testcontainers I found the bind mounts not to be set up correctly. The container is configured this way

2022-07-06 11:41:51,331 DEBUG [org.tes.sha.com.git.doc.cor.com.AbstrDockerCmd] (build-40) Cmd: org.testcontainers.shaded.com.github.dockerjava.core.command.CreateContainerCmdImpl@6a3ee919[aliases=<null>,argsEscaped=<null>,attachStderr=<null>,attachStdin=<null>,attachStdout=<null>,authConfig=<null>,cmd=<null>,domainName=<null>,entrypoint=<null>,env=<null>,exposedPorts=ExposedPorts(exposedPorts=[8080/tcp]),healthcheck=<null>,hostConfig=HostConfig(binds=[/var/run/docker.sock:/var/run/docker.sock:rw], blkioWeight=null, blkioWeightDevice=null, blkioDeviceReadBps=null, blkioDeviceWriteBps=null, blkioDeviceReadIOps=null, blkioDeviceWriteIOps=null, memorySwappiness=null, nanoCPUs=null, capAdd=null, capDrop=null, containerIDFile=null, cpuPeriod=null, cpuRealtimePeriod=null, cpuRealtimeRuntime=null, cpuShares=null, cpuQuota=null, cpusetCpus=null, cpusetMems=null, devices=null, deviceCgroupRules=null, deviceRequests=null, diskQuota=null, dns=null, dnsOptions=null, dnsSearch=null, extraHosts=null, groupAdd=null, ipcMode=null, cgroup=null, links=[], logConfig=LogConfig(type=null, config=null), lxcConf=null, memory=null, memorySwap=null, memoryReservation=null, kernelMemory=null, networkMode=null, oomKillDisable=null, init=null, autoRemove=true, oomScoreAdj=null, portBindings={8080/tcp=[Lcom.github.dockerjava.api.model.Ports$Binding;@7b36550d}, privileged=false, publishAllPorts=null, readonlyRootfs=null, restartPolicy=null, ulimits=null, cpuCount=null, cpuPercent=null, ioMaximumIOps=null, ioMaximumBandwidth=null, volumesFrom=null, mounts=null, pidMode=null, isolation=null, securityOpts=null, storageOpt=null, cgroupParent=null, volumeDriver=null, shmSize=null, pidsLimit=null, runtime=null, tmpFs=null, utSMode=null, usernsMode=null, sysctls=null, consoleSize=null, cgroupnsMode=null),hostName=<null>,image=testcontainers/ryuk:0.3.3,ipv4Address=<null>,ipv6Address=<null>,labels={org.testcontainers=true},macAddress=<null>,name=testcontainers-ryuk-d6f2f4b0-82c0-4e7c-a419-6cc7a3bf4858,networkDisabled=<null>,networkingConfig=<null>,onBuild=<null>,platform=<null>,portSpecs=<null>,shell=<null>,stdInOnce=<null>,stdinOpen=<null>,stopSignal=<null>,stopTimeout=<null>,tty=<null>,user=<null>,volumes=Volumes(volumes=[]),workingDir=<null>]

Did you notice the mount for the docker.sock file ? It is using a hostConfig and an empty volumes configuration. It seems the runtime isn't able to make any sense/use of the hostConfig configuration. To demonstrate the difference that makes to using a volume mount for the file.

$ docker run quay.io/testcontainers/ryuk
2022/07/06 10:02:27 Starting on port 8080...
panic: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

goroutine 1 [running]:
main.main()
	/go/src/github.com/testcontainers/moby-ryuk/main.go:31 +0xe2e
$ docker run quay.io/testcontainers/ryuk -v /var/run/docker.sock:/var/run/docker.sock:rw,z
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "-v": executable file not found in $PATH: unknown.
ERRO[0001] error waiting for container: context canceled 
$

This should explain why you see this error.

As a workaround to the problem you raised why not disable using RYUK being started. It may be completely unnecessary. Using the environment variable TESTCONTAINERS_RYUK_DISABLED to control RYUK.

export TESTCONTAINERS_RYUK_DISABLED=true

whitingjr avatar Jul 06 '22 11:07 whitingjr