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
- Use a 2021 MacBook Pro with M1 Chip.
- Check out the repo: https://github.com/therealjsie/rdtc-test
- Run
mvn verifywith Rancher Desktop (Kubernetes disabled, usingdockerdruntime) - 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 2 years ago
- Reactions: 6
- Comments: 37 (7 by maintainers)
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:
Things have worked out for me when I enabled the option
Allow Rancher Desktop to acquire administrative credentials (sudo access)inPreferences > Application > BehaviormenuIf 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:
This is possible because
vzNATnetworking 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.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.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-979516106The
mvn verifycommand 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:Output:
This requires that you run Rancher Desktop with admin access enabled, so it will allocate a routable IP:
Same here - https://github.com/quarkusio/quarkus/issues/25682
Running
rdctl shell ip a show vznatI getip: can't find device 'vznat'Rancher Desktop 1.13.1 for aarch64 on M3
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 🙌
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
Thank you very much for the help!
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.