Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Could not connect to Ryuk when running Testcontainers in Docker Desktop on Mac OS #7036

Closed
jxblum opened this issue May 12, 2023 · 9 comments
Labels

Comments

@jxblum
Copy link

jxblum commented May 12, 2023

Module

Cassandra

Testcontainers version

1.18.1

Using the latest Testcontainers version?

Yes

Host OS

Mac OS

Host Arch

x86 64

Docker version

m$ docker version
Client:
 Cloud integration: v1.0.31
 Version:           23.0.5
 API version:       1.42
 Go version:        go1.19.8
 Git commit:        bc4487a
 Built:             Wed Apr 26 16:12:52 2023
 OS/Arch:           darwin/amd64
 Context:           default

Server: Docker Desktop 4.19.0 (106363)
 Engine:
  Version:          23.0.5
  API version:      1.42 (minimum version 1.12)
  Go version:       go1.19.8
  Git commit:       94d3ad6
  Built:            Wed Apr 26 16:17:45 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.20
  GitCommit:        2806fc1057397dbaeefbea0e4e17bddfbd388f38
 runc:
  Version:          1.1.5
  GitCommit:        v1.1.5-0-gf19387a
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

What happened?

This: #4395 (comment)

I am running Mac OS 13.3.1, using Docker Desktop 4.19.0 (106363) and Testcontainers 1.18.1

When using the Cassandra Testcontainer in particular, on cassandraContainer.start(), I am still seeing the following Exception being thrown:

Caused by: java.lang.IllegalStateException: Could not connect to Ryuk at 172.17.0.1:59391
	at org.testcontainers.utility.RyukResourceReaper.maybeStart(RyukResourceReaper.java:132)
	at org.testcontainers.utility.RyukResourceReaper.init(RyukResourceReaper.java:42)
	at org.testcontainers.DockerClientFactory.client(DockerClientFactory.java:224)
	at org.testcontainers.DockerClientFactory$1.getDockerClient(DockerClientFactory.java:104)
	at com.github.dockerjava.api.DockerClientDelegate.authConfig(DockerClientDelegate.java:109)
	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:321)
	at example.app.crm.config.TestcontainersCassandraConfiguration.cassandraContainer(TestcontainersCassandraConfiguration.java:71)
...

Relevant log output

No response

Additional Information

Again, this: #4395 (comment)

@jxblum
Copy link
Author

jxblum commented May 12, 2023

Copy from comment in Issue #4395.

/var/run/docker.sock.raw is not even a file on macOS 13.3.1 with Docker Desktop 4.19.0 (106363) using Testcontainers 1.18.1:

$ ls -la /var/run/docker.sock.raw
ls: /var/run/docker.sock.raw: No such file or directory

I still see:

Caused by: java.lang.IllegalStateException: Could not connect to Ryuk at 172.17.0.1:59391
	at org.testcontainers.utility.RyukResourceReaper.maybeStart(RyukResourceReaper.java:132)
	at org.testcontainers.utility.RyukResourceReaper.init(RyukResourceReaper.java:42)
	at org.testcontainers.DockerClientFactory.client(DockerClientFactory.java:224)
	at org.testcontainers.DockerClientFactory$1.getDockerClient(DockerClientFactory.java:104)
	at com.github.dockerjava.api.DockerClientDelegate.authConfig(DockerClientDelegate.java:109)
	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:321)
	at example.app.crm.config.TestcontainersCassandraConfiguration.cassandraContainer(TestcontainersCassandraConfiguration.java:71)
...
..
.

I am attempting to run tests using Testcontainers to bootstrap a Apache Cassandra 3.11.15 container with:

$ docker run -it --mount type=bind,source="$(pwd)",target=/source-from-github -v /var/run/docker.sock:/var/run/docker.sock -v /usr/local/bin/docker:/usr/local/bin/docker eclipse-temurin:17.0.6_10-jdk-focal /bin/bash

Essentially, bootstrapping the Cassandra container with:

	private static final DockerImageName CASSANDRA_DOCKER_IMAGE_NAME = DockerImageName.parse("cassandra:3.11.15");

	private static final String LOCAL_DATACENTER_NAME = "datacenter1";

	private static final int CASSANDRA_DEFAULT_PORT = 9042;

	@Bean("CassandraContainer")
	GenericContainer<?> cassandraContainer(Environment environment) {

		GenericContainer<?> cassandraContainer = newEnvironmentOptimizedCassandraContainer();

71:		cassandraContainer.start();

		return withCassandraServer(cassandraContainer, environment);
	}

	private @NonNull GenericContainer<?> newCassandraContainer() {

		return new CassandraContainer<>(CASSANDRA_DOCKER_IMAGE_NAME)
			.withInitScript(CASSANDRA_SCHEMA_CQL)
			//.withInitScript(CASSANDRA_INIT_CQL)
			.withExposedPorts(CASSANDRA_DEFAULT_PORT)
			.withReuse(true);
	}

	private @NonNull GenericContainer<?> newEnvironmentOptimizedCassandraContainer() {

		return newCassandraContainer()
			.withEnv("CASSANDRA_SNITCH", "SimpleSnitch")
			.withEnv("HEAP_NEWSIZE", "128M")
			.withEnv("MAX_HEAP_SIZE", "1024M")
			.withEnv("JVM_OPTS", "-Dcassandra.skip_wait_for_gossip_to_settle=0 -Dcassandra.initial_token=0");
	}

	private @NonNull CqlSession newCqlSession(@NonNull GenericContainer<?> cassandraContainer) {

		return CqlSession.builder()
			.addContactPoint(resolveContactPoint(cassandraContainer))
			.withLocalDatacenter(LOCAL_DATACENTER_NAME)
			.build();
	}

	private @NonNull InetSocketAddress resolveContactPoint(@NonNull GenericContainer<?> cassandraContainer) {
		return new InetSocketAddress(cassandraContainer.getHost(),
			cassandraContainer.getMappedPort(CASSANDRA_DEFAULT_PORT));
	}

@jxblum jxblum changed the title [Bug]: Could not connect to Ryuk when running Testcontainers in Docker Desktop Could not connect to Ryuk when running Testcontainers in Docker Desktop on Mac OS May 13, 2023
@jxblum jxblum changed the title Could not connect to Ryuk when running Testcontainers in Docker Desktop on Mac OS [Bug]: Could not connect to Ryuk when running Testcontainers in Docker Desktop on Mac OS May 13, 2023
@grv95
Copy link

grv95 commented May 16, 2023

+1
Facing the same issue on Mac m1 arm64 machine.

@eddumelendez
Copy link
Member

Hi, IIRC latest version of Docker Desktop doesn't provide /var/run/docker.sock by default. In order to enable it should go to Settings > Advanced and make sure Enable default Docker socket (Requires password) is checked.

Rootless is still not supported for Docker Desktop for Mac and Linux.

Hope this help.

@ph4r5h4d
Copy link

I have the same issue; I have an M1 mac with the Docker for desktop and the Docker socket is enabled and accessible in /var/run/docker.sock but I can't use test container 1.18.1 as it fails with the following error:

Could not find a valid Docker environment. Please check configuration.

The same thing works with 1.17.6

@eddumelendez
Copy link
Member

@ph4r5h4d can you share your logs? Also, this is a different issue I think. In the meantime, can we go move to discussion, please?

@grv95
Copy link

grv95 commented May 16, 2023

@eddumelendez
I already have the default docker socket enabled.
It is available for me as /var/run/docker.sock instead of /var/run/docker.sock.raw

still can't connect to Ryuk
Other containers are working fine.

@eddumelendez
Copy link
Member

Hi, IIRC latest version of Docker Desktop doesn't provide /var/run/docker.sock by default. In order to enable it should go to Settings > Advanced and make sure Enable default Docker socket (Requires password) is checked.

Rootless is still not supported for Docker Desktop for Mac and Linux.

Hope this help.

Testcontainers for Java 1.18.2 will auto-detect ~/.docker/run/docker.sock. So, no more workarounds are needed.

@demeralde
Copy link

Has anyone figured out how to fix this error? I'm getting it on my M3 Pro device. When I set this env var, the exact same test succeeds:

os.Setenv("TESTCONTAINERS_RYUK_DISABLED", "true")

@upeter
Copy link

upeter commented Aug 14, 2024

The only way I could get it solved on my M2 Pro is via -e TESTCONTAINERS_HOST_OVERRIDE=host.docker.internal. Then it worked flawlessly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants