Skip to content

Unable to run test containers with Apple Silicon Mac #3834

Closed

Description

@sdelamo
% 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"

Activity

  1. bsideup commented on Feb 25, 2021

    @bsideup
    Member

    @sdelamo please share the full log

  2. ansotolab commented on Feb 25, 2021

    @ansotolab

    @bsideup I have the same issue and I wrote it here #3810

  3. bsideup commented on Feb 25, 2021

    @bsideup
    Member

    @ansotolab I do not think you have the same issue. In your case, the environment detection works fine.

  4. ansotolab commented on Feb 25, 2021

    @ansotolab

    @bsideup sorry it could be my fault because I wrote two comments on the same issue, I'm talking about the first one #3810 (comment) 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 configuration

    The second comment #3810 (comment) 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.

  5. sdelamo commented on Mar 2, 2021

    @sdelamo
    Author

    @bsideup Not sure how if this is the log you mentioned:

    16:30:05.406 [Test worker] WARN  o.t.u.TestcontainersConfiguration - Attempted to read Testcontainers configuration file at file:/Users/sdelamo/.testcontainers.properties but the file was not found. Exception message: FileNotFoundException: /Users/sdelamo/.testcontainers.properties (No such file or directory)
    16:30:05.413 [Test worker] INFO  o.t.d.DockerMachineClientProviderStrategy - docker-machine executable was not found on PATH ([/usr/bin, /bin, /usr/sbin, /sbin])
    16:30:05.630 [Test worker] ERROR o.t.d.DockerClientProviderStrategy - Could not find a valid Docker environment. Please check configuration. Attempted configurations were:
    16:30:05.631 [Test worker] ERROR o.t.d.DockerClientProviderStrategy -     UnixSocketClientProviderStrategy: failed with exception RuntimeException (java.lang.UnsatisfiedLinkError: /Users/sdelamo/Library/Caches/JNA/temp/jna14927840726792078170.tmp: dlopen(/Users/sdelamo/Library/Caches/JNA/temp/jna14927840726792078170.tmp, 1): no suitable image found.  Did find:
    	/Users/sdelamo/Library/Caches/JNA/temp/jna14927840726792078170.tmp: no matching architecture in universal wrapper
    	/Users/sdelamo/Library/Caches/JNA/temp/jna14927840726792078170.tmp: no matching architecture in universal wrapper). Root cause UnsatisfiedLinkError (/Users/sdelamo/Library/Caches/JNA/temp/jna14927840726792078170.tmp: dlopen(/Users/sdelamo/Library/Caches/JNA/temp/jna14927840726792078170.tmp, 1): no suitable image found.  Did find:
    	/Users/sdelamo/Library/Caches/JNA/temp/jna14927840726792078170.tmp: no matching architecture in universal wrapper
    	/Users/sdelamo/Library/Caches/JNA/temp/jna14927840726792078170.tmp: no matching architecture in universal wrapper)
    16:30:05.631 [Test worker] ERROR o.t.d.DockerClientProviderStrategy - As no valid configuration was found, execution cannot continue
    
    java.lang.ExceptionInInitializerError
    	at java.base/java.lang.Class.forName(Class.java:398)
    	at uk.co.metadataworks.mdximport.MySqlTestPropertyProvider$Trait$Helper.url(MySqlTestPropertyProvider.groovy:8)
    	at uk.co.metadataworks.mdximport.DatabaseTestPropertyProvider$Trait$Helper.getProperties(DatabaseTestPropertyProvider.groovy:12)
    	at uk.co.metadataworks.mdximport.repositories.DataModelRepositorySpec.getConfiguration(DataModelRepositorySpec.groovy:17)
    	at uk.co.metadataworks.mdximport.ApplicationContextSpecification.$spock_initializeSharedFields(ApplicationContextSpecification.groovy:12)
    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 uk.co.metadataworks.mdximport.MySql.init(MySql.groovy:16)
    	at uk.co.metadataworks.mdximport.MySql.<clinit>(MySql.groovy:10)
    	... 5 more
    
    
    DataModelRepositorySpec > initializationError FAILED
        java.lang.ExceptionInInitializerError at DataModelRepositorySpec.groovy:17
            Caused by: java.lang.IllegalStateException at DataModelRepositorySpec.groovy:17
    1 test completed, 1 failed
    
  6. bsideup commented on Mar 2, 2021

    @bsideup
    Member

    @sdelamo it is, thanks :)

    Your problem is related to JNA:

    /Users/sdelamo/Library/Caches/JNA/temp/jna14927840726792078170.tmp: no matching architecture in universal wrapper

    Consider either using JNA 5.7.0 that is compatible with M1 or use x86 build of JDK.

  7. ikattey commented on Mar 2, 2021

    @ikattey

    I can confirm that adding the following Maven dependency fixed this issue for me:

     <dependency>
                   <groupId>net.java.dev.jna</groupId>
                    <artifactId>jna</artifactId>
                   <version>5.7.0</version>
                    <scope>test</scope>
    </dependency>
    
  8. sdelamo commented on Mar 3, 2021

    @sdelamo
    Author

    Thanks @bsideup and @ikattey

    Now I get a different error:

    java.lang.ExceptionInInitializerError
    	at java.base/java.lang.Class.forName(Class.java:398)
    	at uk.co.metadataworks.mdximport.MySqlTestPropertyProvider$Trait$Helper.url(MySqlTestPropertyProvider.groovy:8)
    	at uk.co.metadataworks.mdximport.DatabaseTestPropertyProvider$Trait$Helper.getProperties(DatabaseTestPropertyProvider.groovy:12)
    	at uk.co.metadataworks.mdximport.repositories.DataModelRepositorySpec.getConfiguration(DataModelRepositorySpec.groovy:17)
    	at uk.co.metadataworks.mdximport.ApplicationContextSpecification.$spock_initializeSharedFields(ApplicationContextSpecification.groovy:12)
    Caused by: org.testcontainers.containers.ContainerLaunchException: Container startup failed
    	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:330)
    	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:311)
    	at uk.co.metadataworks.mdximport.MySql.init(MySql.groovy:16)
    	at uk.co.metadataworks.mdximport.MySql.<clinit>(MySql.groovy:10)
    	... 5 more
    Caused by: org.testcontainers.containers.ContainerFetchException: Can't get Docker image: RemoteDockerImage(imageName=mysql:5.7.28, imagePullPolicy=DefaultPullPolicy())
    	at org.testcontainers.containers.GenericContainer.getDockerImageName(GenericContainer.java:1286)
    	at org.testcontainers.containers.GenericContainer.logger(GenericContainer.java:615)
    	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:320)
    	... 8 more
    Caused by: org.testcontainers.containers.ContainerFetchException: Failed to get Docker client for mysql:5.7.28
    	at org.testcontainers.images.RemoteDockerImage.resolve(RemoteDockerImage.java:99)
    	at org.testcontainers.images.RemoteDockerImage.resolve(RemoteDockerImage.java:27)
    	at org.testcontainers.utility.LazyFuture.getResolvedValue(LazyFuture.java:17)
    	at org.testcontainers.utility.LazyFuture.get(LazyFuture.java:39)
    	at org.testcontainers.containers.GenericContainer.getDockerImageName(GenericContainer.java:1284)
    	... 10 more
    Caused by: com.github.dockerjava.api.exception.DockerClientException: Could not pull image: no matching manifest for linux/arm64/v8 in the manifest list entries
    	at com.github.dockerjava.api.command.PullImageResultCallback.checkDockerClientPullSuccessful(PullImageResultCallback.java:97)
    	at com.github.dockerjava.api.command.PullImageResultCallback.throwFirstError(PullImageResultCallback.java:112)
    	at com.github.dockerjava.api.async.ResultCallbackTemplate.awaitCompletion(ResultCallbackTemplate.java:93)
    	at org.testcontainers.images.TimeLimitedLoggedPullImageResultCallback.awaitCompletion(TimeLimitedLoggedPullImageResultCallback.java:52)
    	at org.testcontainers.images.RemoteDockerImage.resolve(RemoteDockerImage.java:82)
    	... 14 more
    

    I am able to download this docker image in an Intel Mac.

  9. dizney commented on Mar 11, 2021

    @dizney

    @sdelamo mysql does not provide arm images. For example https://hub.docker.com/_/mariadb does provide them, so you might try that.

  10. rdehuyss commented on Apr 21, 2021

    @rdehuyss

    For those working with Gradle, adding the following solved the issue for me:

    testImplementation 'net.java.dev.jna:jna-platform:5.8.0'

  11. bsideup commented on Apr 21, 2021

    @bsideup
    Member

    FYI Testcontainers 1.15.3 is released now and depends on 5.8.0 by default.

  12. rdehuyss commented on Apr 22, 2021

    @rdehuyss

    @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

  13. bsideup commented on Apr 23, 2021

    @bsideup
    Member

    @rdehuyss it is really a question to Gradle and not Testcontainers :)

    Someone pointed out that visible-assertions also depends on JNA (5.2.0) and that some build systems for some reason prioritize it over docker-java-transport:
    #4008 (comment)

    To help with that, since visible-assertions isn't used by our main classpath anymore, we plan to remove it as a dependency in the next release. You can also try excluding org.rnorth.visible-assertions:visible-assertions already today, just to check whether that's the case

  14. wimdeblauwe commented on Jul 20, 2021

    @wimdeblauwe
    Contributor

    When using Maven with Testcontainers 1.15.3, you can exclude visible-assertions like this:

            <dependency>
                <groupId>org.testcontainers</groupId>
                <artifactId>junit-jupiter</artifactId>
                <scope>test</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.rnorth.visible-assertions</groupId>
                        <artifactId>visible-assertions</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
    
  15. 11 remaining items

  16. dicolasi commented on Sep 17, 2021

    @dicolasi

    tried in multiple ways, seems impossible to get those logs.

  17. TranquilMarmot commented on Sep 20, 2021

    @TranquilMarmot

    I'm on testcontainers version 1.16.0 and it still does not work on my M1 Mac.

    ➜  ~ java -version
    openjdk version "11.0.10" 2021-01-19 LTS
    OpenJDK Runtime Environment (build 11.0.10+9-LTS)
    OpenJDK 64-Bit Server VM (build 11.0.10+9-LTS, mixed mode)
    

    Here are the logs:

    2021-09-20 10:50:13.073  INFO [api,,] 52788 --- [           main] .t.d.DockerMachineClientProviderStrategy : docker-machine executable was not found on PATH ([/opt/homebrew/opt/helm@2/bin, /Users/nate/.asdf/shims, /opt/homebrew/opt/asdf/bin, /opt/homebrew/bin, /opt/homebrew/sbin, /usr/local/bin, /usr/bin, /bin, /usr/sbin, /sbin])
    2021-09-20 10:50:14.122 ERROR [api,,] 52788 --- [           main] o.t.d.DockerClientProviderStrategy       : Could not find a valid Docker environment. Please check configuration. Attempted configurations were:
    2021-09-20 10:50:14.122 ERROR [api,,] 52788 --- [           main] o.t.d.DockerClientProviderStrategy       :     UnixSocketClientProviderStrategy: failed with exception RuntimeException (java.lang.UnsatisfiedLinkError: /Users/nate/Library/Caches/JNA/temp/jna12712874903713535509.tmp: dlopen(/Users/nate/Library/Caches/JNA/temp/jna12712874903713535509.tmp, 1): no suitable image found.  Did find:
    	/Users/nate/Library/Caches/JNA/temp/jna12712874903713535509.tmp: no matching architecture in universal wrapper
    	/Users/nate/Library/Caches/JNA/temp/jna12712874903713535509.tmp: no matching architecture in universal wrapper). Root cause UnsatisfiedLinkError (/Users/nate/Library/Caches/JNA/temp/jna12712874903713535509.tmp: dlopen(/Users/nate/Library/Caches/JNA/temp/jna12712874903713535509.tmp, 1): no suitable image found.  Did find:
    	/Users/nate/Library/Caches/JNA/temp/jna12712874903713535509.tmp: no matching architecture in universal wrapper
    	/Users/nate/Library/Caches/JNA/temp/jna12712874903713535509.tmp: no matching architecture in universal wrapper)
    2021-09-20 10:50:14.122 ERROR [api,,] 52788 --- [           main] o.t.d.DockerClientProviderStrategy       : As no valid configuration was found, execution cannot continue
    2021-09-20 10:50:14.133 ERROR [api,,] 52788 --- [           main] o.s.boot.SpringApplication               : Application run failed
    
    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:135)
    	at org.testcontainers.DockerClientFactory.client(DockerClientFactory.java:177)
    	at org.testcontainers.LazyDockerClient.getDockerClient(LazyDockerClient.java:14)
    	at org.testcontainers.LazyDockerClient.authConfig(LazyDockerClient.java:12)
    	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:314)
    	at com.cb.db.DbContainerInitializer.initialize(RepositoryTest.kt:96)
    

    I tried explicitly adding jna dependencies but they didn't help:

    <dependency>
        <groupId>net.java.dev.jna</groupId>
        <artifactId>jna</artifactId>
        <version>5.9.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>net.java.dev.jna</groupId>
        <artifactId>jna-platform</artifactId>
        <version>5.9.0</version>
        <scope>test</scope>
    </dependency>
    

    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-elasticsearch was pulling in an old/bad version of JNA and we upgraded that dependency (it's now on 7.13.4)

  18. jonydog commented on Dec 20, 2021

    @jonydog

    Also had this issue with M1 Mac, adding

    <dependency>
       <groupId>net.java.dev.jna</groupId>
        <artifactId>jna</artifactId>
       <version>5.7.0</version>
        <scope>test</scope>
    </dependency>
    

    fixed the issue.

  19. kingboy2903 commented on Mar 10, 2022

    @kingboy2903

    I have same issue with M1 Pro. And this will be solved with upgrade test container to newest version and add dependency jna

            <dependency>
                <groupId>org.testcontainers</groupId>
                <artifactId>mysql</artifactId>
                <version>1.16.3</version>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>net.java.dev.jna</groupId>
                <artifactId>jna</artifactId>
                <version>5.10.0</version>
                <scope>test</scope>
            </dependency>
    
  20. Anatoly4444 commented on Apr 16, 2022

    @Anatoly4444

    same problem with mac 2021

  21. bibinss commented on Jun 18, 2022

    @bibinss

    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 library net.snowflake:snowflake-jdbc.3.12.10 in 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 latest net.snowflake:snowflake-jdbc.3.13.19 to resolve the issue. It took me a while to figure out the issue, but was relieved finally :)

  22. shubhimohta commented on Jul 13, 2022

    @shubhimohta

    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.

    testImplementation('net.java.dev.jna:jna-platform'){
            version {
                strictly("[5.7,5.10]")
            }
        } 
    

    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)

  23. JohnnyMarnell commented on Aug 10, 2022

    @JohnnyMarnell

    This thread saved me 🙏 , in our case I needed to exclude JNA jars from very old elasticsearch version, e.g.:

    <dependency>
          <groupId>org.elasticsearch</groupId>
          <artifactId>elasticsearch</artifactId>
          <exclusions>
            <exclusion>
              <groupId>org.elasticsearch</groupId>
              <artifactId>jna</artifactId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>

    Ended up adding maven enforcer rule like:

              <plugin>
                <artifactId>maven-enforcer-plugin</artifactId>
                <configuration>
                  <rules>
                    <bannedDependencies>
                      <excludes>
                        <exclude>org.elasticsearch:jna</exclude>
                      </excludes>
                      <message>org.elasticsearch:jna is incompatible with arm64 / Apple M1, use net.java.dev.jna:jna instead</message>
                    </bannedDependencies>
                  </rules>
                </configuration>
              </plugin>
  24. JohnnyMarnell commented on Sep 14, 2022

    @JohnnyMarnell

    happening again for me, this time no other JNA though

  25. AndyLau223 commented on Sep 22, 2022

    @AndyLau223

    Thanks for all the active comments. This issue happens on my machine(Mac M1), and the solution of adding testImplementation 'net.java.dev.jna:jna-platform:5.8.0' into build.gradle file works fine for me, now the tests are running smoothly.

  26. harihara6 commented on Jun 15, 2023

    @harihara6

    For those running test containers on Mac M2, ( if withPlatform override is not supported on your versions), I did this

    Just removed existing images

    docker system prune -af

    I pulled the latest myself

    docker pull arm64v8/mysql

    and tagged it the way I want

    docker tag arm64v8/mysql:latest mysql:5.7.22

    Now the tests are running as expected.

  27. fatso83 commented on Sep 21, 2023

    @fatso83

    Just a little note for you others that have tried all the tips above, updating dependencies and exluding jna's to no avail: There's one other thing that will also make the tests fail with docker-machine executable was not found on PATH ...

    If you try running any Docker command, like docker ps and get cannot connect to the Docker daemon, you have forgotten to start the Docker daemon. Don't ask me how I know 🙈 Start it up and then re-rerun your tests 👍

  28. swar8080 commented on Oct 11, 2023

    @swar8080

    For anyone using docker desktop that's hitting issues starting the testcontainer/ryuk image, I had to enable the Allow the default Docker socket to be used (requires password) setting to fix it:

    image
  29. eddumelendez commented on Oct 11, 2023

    @eddumelendez
    Member

    You don't need that option with latest versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions