testcontainers-java: Unable to run test containers with Apple Silicon Mac
% docker version
Client: Docker Engine - Community
Cloud integration: 1.0.8
Version: 20.10.3
API version: 1.41
Go version: go1.13.15
Git commit: 48d30b5
Built: Fri Jan 29 14:28:27 2021
OS/Arch: darwin/amd64 (rosetta)
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.3
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: 46229ca
Built: Fri Jan 29 14:32:07 2021
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.4.3
GitCommit: 269548fa27e0089a8b8278fc4fc781d7f65a939b
runc:
Version: 1.0.0-rc92
GitCommit: ff819c7e9184c13b7c2607fe6c30ae19403a7aff
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Running docker via Docker Desktop Preview Version 3.1.0(60984) Disabled: Use gRPC FUSE for file sharing
Error:
Caused by: java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configuration
at org.testcontainers.dockerclient.DockerClientProviderStrategy.lambda$getFirstValidStrategy$7(DockerClientProviderStrategy.java:215)
at java.base/java.util.Optional.orElseThrow(Optional.java:408)
at org.testcontainers.dockerclient.DockerClientProviderStrategy.getFirstValidStrategy(DockerClientProviderStrategy.java:207)
at org.testcontainers.DockerClientFactory.getOrInitializeStrategy(DockerClientFactory.java:136)
at org.testcontainers.DockerClientFactory.client(DockerClientFactory.java:178)
at org.testcontainers.LazyDockerClient.getDockerClient(LazyDockerClient.java:14)
at org.testcontainers.LazyDockerClient.authConfig(LazyDockerClient.java:12)
at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:310)
at example.mycompany.MySql.init(MySql.groovy:16)
at example.mycompany.MySql.<clinit>(MySql.groovy:10)
... 5 more
Using test containers in a Gradle build
testImplementation(platform("org.testcontainers:testcontainers-bom:1.15.2"))
testImplementation("org.testcontainers:mysql")
testImplementation "org.testcontainers:selenium"
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 14
- Comments: 39 (12 by maintainers)
I can confirm that adding the following Maven dependency fixed this issue for me:
@sdelamo it is, thanks š
Your problem is related to JNA:
Consider either using JNA 5.7.0 that is compatible with M1 or use x86 build of JDK.
I have same issue with M1 Pro. And this will be solved with upgrade test container to newest version and add dependency
jnaFor those working with Gradle, adding the following solved the issue for me:
testImplementation 'net.java.dev.jna:jna-platform:5.8.0'This thread saved me š , in our case I needed to exclude JNA jars from very old elasticsearch version, e.g.:
Ended up adding maven enforcer rule like:
For me even after explicitly mentioning the dependency
testImplementation 'net.java.dev.jna:jna-platform:5.8.0', it did not work for me as one of the transitive dependency was using jna version 4.5.1. (transitive dependencies are dependencies that your component needs, but only because another dependency needs them)So I had to force gradle to pick the newer version of jna which worked for me.
Here is the reference to how to declare versions like I did above: https://docs.gradle.org/current/userguide/rich_versions.html#sec:strict-version
One can select what works for them, but since any version above 5.7 is compatible I have used this. (edited)
@sdelamo mysql does not provide arm images. For example https://hub.docker.com/_/mariadb does provide them, so you might try that.
Iām on
testcontainersversion1.16.0and it still does not work on my M1 Mac.Here are the logs:
I tried explicitly adding
jnadependencies but they didnāt help:Update: After pulling from our main branch, this started working again. I havenāt narrowed it down but I think that
org.springframework.data.spring-data-elasticsearchwas pulling in an old/bad version of JNA and we upgraded that dependency (itās now on7.13.4)@rdehuyss it is really a question to Gradle and not Testcontainers š
Someone pointed out that
visible-assertionsalso depends on JNA (5.2.0) and that some build systems for some reason prioritize it overdocker-java-transport: https://github.com/testcontainers/testcontainers-java/issues/4008#issuecomment-824617867To help with that, since
visible-assertionsisnāt used by our main classpath anymore, we plan to remove it as a dependency in the next release. You can also try excludingorg.rnorth.visible-assertions:visible-assertionsalready today, just to check whether thatās the caseYou donāt need that option with latest versions.
In my case I was seeing the
java.lang.UnsatisfiedLinkError: Can't load library:even after upgrading jna lib version to 5.7.0. Further debugging showed that I had another librarynet.snowflake:snowflake-jdbc.3.12.10in the class path which had the same jna (com.sun.jnaā¦) code in it. So at run time, my JVM was loading the one from snowflake jar causing the failure. I upgraded to latestnet.snowflake:snowflake-jdbc.3.13.19to resolve the issue. It took me a while to figure out the issue, but was relieved finally šI am seeing the same problem with v1.16.0 and jna v5.8.0
@bsideup indeed, I see it - however, for me it only works if I add the
testImplementation 'net.java.dev.jna:jna-platform:5.8.0'. Canāt explain why yet - maybe because Iām using gradle platform to manage my dependencies?To reproduce, see: https://github.com/jobrunr/jobrunr/blob/silicon-mac/core/build.gradle#L52-L53
Any test that uses TestContainers will fail like
LettuceRedisStorageProvider@bsideup sorry it could be my fault because I wrote two comments on the same issue, Iām talking about the first one https://github.com/testcontainers/testcontainers-java/issues/3810#issuecomment-783221149 you can see there is an error log dropdown. In it appears:
09:54:24.871 [main] ERROR org.testcontainers.dockerclient.DockerClientProviderStrategy - Could not find a valid Docker environment. Please check configuration. Attempted configurations were:java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configurationThe second comment https://github.com/testcontainers/testcontainers-java/issues/3810#issuecomment-783231622 is a temporary solution. If I run the testcontainers inside Docker I didnāt receive any error but itās not the best option for development.