rancher-desktop: Running Testcontainers with Rancher Desktop and Apple Silicon fails

Actual Behavior

Running a test using Testcontainers on a MacBook Pro M1 leads to exceptions and a failed test with Rancher Desktop. Using the same setup with Docker Desktop does not result in a failed test.

Steps to Reproduce

  1. Use a 2021 MacBook Pro with M1 Chip.
  2. Check out the repo: https://github.com/therealjsie/rdtc-test
  3. Run mvn verify with Rancher Desktop (Kubernetes disabled, using dockerd runtime)
  4. Should result in a failed test.

Result

Failing logs with Rancher Desktop: repo-postgres-simple-test-macos-m1.log

Expected Behavior

Successful logs with Docker Desktop: repo-postgres-simple-test-macos-m1-docker-desktop.log

Additional Information

No response

Rancher Desktop Version

1.4.1

Rancher Desktop K8s Version

disabled

Which container runtime are you using?

moby (docker cli)

What operating system are you using?

macOS

Operating System / Build Version

macOs Monterey 12.4

What CPU architecture are you using?

arm64 (Apple Silicon)

Linux only: what package format did you use to install Rancher Desktop?

N/A

Windows User Only

No response

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 8
  • Comments: 52 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Maybe this helps some others, but looking at a similar problem, I found this to work with the provided example under Colima which exhibited the same problem, adding in a wait strategy to ensure the external port was mapped:

                .withPassword("PWD")
                .waitingFor(Wait.forListeningPort()))

Running rdctl shell ip a show vznat I get ip: can't find device 'vznat'

Rancher Desktop 1.13.1 for aarch64 on M3 Screenshot 2024-04-25 at 13 52 21

Things have worked out for me when I enabled the option Allow Rancher Desktop to acquire administrative credentials (sudo access) in Preferences > Application > Behavior menu

o.t.utility.RyukResourceReaper - Can not connect to Ryuk at localhost:32782

I don’t think you have set the environment variables correctly if the error message still mentions localhost. It should have connected to the IP address specified in TESTCONTAINERS_HOST_OVERRIDE. Are you sure you set end exported all the variables?

I had them, it finally worked after reinstalling Rancher Desktop and restarted the computer, with VZ emulation without administrative credentials and the environment variables in .zshrc

export PATH=$PATH:$HOME/.rd/bin
export DOCKER_HOST=unix://$HOME/.rd/docker.sock
export TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock
export TESTCONTAINERS_HOST_OVERRIDE=$(rdctl shell ip a show vznat | awk '/inet / {sub("/.*",""); print $2}')

Thank you very much for the help!

If you are using VZ emulation (requires macOS 13.3+ Ventura), then you can also get it to work without administrative access by exporting 2 more settings:

export DOCKER_HOST=unix://$HOME/.rd/docker.sock
export TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock
export TESTCONTAINERS_HOST_OVERRIDE=$(rdctl shell ip a show vznat | awk '/inet / {sub("/.*",""); print $2}')

This is possible because vzNAT networking doesn’t require admin access to allocate a routable IP address. It is automatically enabled with VZ emulation, but only in the just release Rancher Desktop 1.10.0.

Image

Whilst I have no comment on @Fonzerelli13’s general answer, I would comment that maybe instead of:

just type ifconfig in termial to list all interfaces and fined one with ip v4 address

You might find it easier to do:

export TESTCONTAINERS_HOST_OVERRIDE=$(ifconfig $(route -n get 0.0.0.0 | grep -F interface | cut -d: -f2) | awk '/inet / {print $2}')

This will print the IP address associated with the default route (i.e. the one your internet traffic is going over).

Disclaimer: Read up on all commands before running them, run at your own risk, yada yada yada 😉

I’m using a M3 Pro MacBook Pro. I enabled VZ and Rosetta and set up the following variables in my .zshrc:

export DOCKER_HOST=unix://$HOME/.rd/docker.sock
export TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock
export TESTCONTAINERS_HOST_OVERRIDE=$(rdctl shell ip a show vznat | awk '/inet / {sub("/.*",""); print $2}')

But the weird thing that happened to me was that, despite having that same error being thrown in my shell:

I get ip: can't find device 'vznat'

I was still able to run the tests in IntelliJ. I figured that there had to be some kind of default value when the TESTCONTAINERS_HOST_OVERRIDE variable is empty. Looking at the logs, it seems that this default value is just localhost. I tried overriding it with localhost in my IntelliJ run configuration and it is working just fine. So I guess you could remove the TESTCONTAINERS_HOST_OVERRIDE variable or set it to an empty string (or to localhost).

Hi @Fonzerelli13

I had to add additional Wait.forListeningPort() strategy to my PostgreSQL testcontainer in order to work on my MacBook Pro M1. This was related to another Lima specific problem with a delay in port forwarding: https://github.com/abiosoft/colima/issues/71#issuecomment-979516106

private static final PostgreSQLContainer<?> POSTGRESQL_CONTAINER = new PostgreSQLContainer<>(DockerImageName.parse("postgres:15.4"))
      .withUsername(USERNAME)
      .withPassword(PASSWORD)
      .withDatabaseName(SCHEMA)
      .waitingFor(new WaitAllStrategy()
          .withStrategy(Wait.forListeningPort())
          .withStrategy(Wait.forLogMessage(".*database system is ready to accept connections.*\\s", 2)
              .withStartupTimeout(Duration.ofSeconds(60))
          )
      );

I am running Rancher Desktop v1.6.2 and still have “Connection Refused” errors when talking to TestContainers embedded Postgres. Docker Desktop seems to work fine, but errors persist with Rancher Desktop. The test mentioned here re-creates the problem well.

Here is the specific error I am seeing in my tests:

java.sql.SQLException: org.postgresql.util.PSQLException: Connection to localhost:49312 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. Caused by: org.postgresql.util.PSQLException: Connection to localhost:49312 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. Caused by: java.net.ConnectException: Connection refused

Oddly, when I manually test the connection while images are running, I am able to connect from Command Prompt.

Observation: If I disable RYUK with export TESTCONTAINERS_RYUK_DISABLED="true" it works like 3 out of 4 times on my M1 MBP. Still, not a solution.

Same issue for me. Running rancher desktop version 1.17.1.

I understand that this comment might be a little bit unethical to make given that this is an issue in Rancher Desktop’s repo, but I wanted to point out that (at least as a temporary solution), Testcontainers Desktop now comes with an embedded runtime that has a built-in solution for this (detecting the IP while the VZ backend is used).

P.S. we (Testcontainers) love Rancher Desktop and even mention it specifically as one of the available local runtime options in Testcontainers Desktop! ❤️ I was just following this thread and did not feel good about all these Testcontainers users who are having issues 🙌

The mvn verify command works for me on Intel, but fails on M1 because ports don’t seem to be forwarded correctly. Not sure yet why. I could work around it by providing the port of the VM explicit:

export TESTCONTAINERS_HOST_OVERRIDE=$(rdctl shell ip a show rd0 | awk '/inet / {sub("/.*",""); print $2}')

Output:

...
[INFO] --- jar:3.3.0:jar (default-jar) @ testcontainers-java-repro ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.565 s
[INFO] Finished at: 2023-09-13T17:07:54-07:00
[INFO] ------------------------------------------------------------------------

This requires that you run Rancher Desktop with admin access enabled, so it will allocate a routable IP:

Image

@onderilkesever @arunmuthiyarkath @onc @michaeldisaro for me this command worked: export TESTCONTAINERS_HOST_OVERRIDE=$(ifconfig en0 | awk '/inet / {print $2}') so, the problem may be in command to show interface address and interface name itself. In my case ifconfig as command ant en as interface name worked. You can just type ifconfig in termial to list all interfaces and fined one with ip v4 address, in my case it was en0.

Still does not work.

Rancher 1.15.0 in default configuration with Kubernetes disabled.

Following https://docs.rancherdesktop.io/how-to-guides/using-testcontainers/

git clone https://github.com/testcontainers/testcontainers-java-repro
cd testcontainers-java-repro
./mvnw verify

First failure:

 Tests in error: 
 demonstration(org.testcontainers.repro.ReproExampleTest): Could not find a valid Docker environment. Please see logs and 
 check configuration

Website forgot to mention DOCKER_HOST but ok

export DOCKER_HOST=unix://$HOME/.rd/docker.sock

Still fails:

. org.testcontainers.containers.ContainerLaunchException: Container startup failed for image testcontainers/ryuk:0.6.0
 Caused by: org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception
. Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
. Caused by: com.github.dockerjava.api.exception.NotFoundException: Status 404: {"message":"No such container: 60a9216f94ea7800b824fd5419aac9f1d8c7c0765ab1248f2d0d82afdb65d72a"}
export TESTCONTAINERS_RYUK_DISABLED=true

BUILD SUCCESS

@kari-jumo I ran into the same thing until I disabled run as administrator and ensured Kubernetes was disabled.

I don’t think this issue is related to the CPU architecture. I’m experiencing the same problem (well the linked Quarkus Issue) on an Intel Mac.