测试容器:在 PATH 上找不到 docker-machine 可执行文件

问题描述 投票:0回答:4

我有两个 Spring Boot 项目,它们都具有相同的 JDK 并且在同一台机器上运行(apple m1)。第一个项目只是一个虚拟项目,其中仅包含 testcontainer 依赖项。

虽然第二个项目是一个遗留项目,我应该在其中集成测试容器。

但是,当 testcontainer 在第一个项目中运行时,对于第二个项目,我收到以下错误(我刚刚从第一个项目复制粘贴了 testcontainer 代码)

JDK:azul 15.0.5

JAVA路径:Library/Java/JavaVirtualMachines/azul-15.0.5/Contents/Home/bin/java Docker 桌面版本:4.5.0

如何解决这个错误?

17:15:41.181 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
17:15:41.189 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
17:15:41.211 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.housing.cron.ListingUpdateBatchContainerTest] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
17:15:41.218 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.housing.cron.ListingUpdateBatchContainerTest], using SpringBootContextLoader
17:15:41.221 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.housing.cron.ListingUpdateBatchContainerTest]: class path resource [com/housing/cron/ListingUpdateBatchContainerTest-context.xml] does not exist
17:15:41.222 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.housing.cron.ListingUpdateBatchContainerTest]: class path resource [com/housing/cron/ListingUpdateBatchContainerTestContext.groovy] does not exist
17:15:41.222 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.housing.cron.ListingUpdateBatchContainerTest]: no resource found for suffixes {-context.xml, Context.groovy}.
17:15:41.222 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.housing.cron.ListingUpdateBatchContainerTest]: ListingUpdateBatchContainerTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
17:15:41.254 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.housing.cron.ListingUpdateBatchContainerTest]
17:15:41.292 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [/Users/pankajkumar/Desktop/workspace/services/jasprr/cron/target/classes/com/housing/cron/CronApplication.class]
17:15:41.293 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.housing.cron.CronApplication for test class com.housing.cron.ListingUpdateBatchContainerTest
17:15:41.360 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.housing.cron.ListingUpdateBatchContainerTest]: using defaults.
17:15:41.360 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.event.ApplicationEventsTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener]
17:15:41.372 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@3f1c5af9, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@1c55f277, org.springframework.test.context.event.ApplicationEventsTestExecutionListener@5ddabb18, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@3e8f7922, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@63192798, org.springframework.test.context.support.DirtiesContextTestExecutionListener@50eca7c6, org.springframework.test.context.transaction.TransactionalTestExecutionListener@58e6d4b8, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@1de5f0ef, org.springframework.test.context.event.EventPublishingTestExecutionListener@376a312c, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@28d6290, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@6ca0256d, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@5ef0d29e, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@38f57b3d, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@51850751, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@3ce3db41]
17:15:41.374 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@1d7f7be7 testClass = ListingUpdateBatchContainerTest, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration@42f3156d testClass = ListingUpdateBatchContainerTest, locations = '{}', classes = '{class com.housing.cron.CronApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.test.context.support.DynamicPropertiesContextCustomizer@46eedc3b, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@6c2ed0cd, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@51133c06, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@5a3bc7ed, org.springframework.boot.test.web.reactive.server.WebTestClientContextCustomizer@4671115f, org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@46b61c56, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@68df9280, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@f2f2cc1], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map[[empty]]], class annotated with @DirtiesContext [false] with mode [null].
17:15:41.421 [main] DEBUG org.testcontainers.utility.TestcontainersConfiguration - Testcontainers configuration overrides will be loaded from file:/Users/pankajkumar/.testcontainers.properties
17:15:41.430 [main] INFO org.testcontainers.dockerclient.DockerClientProviderStrategy - Loaded org.testcontainers.dockerclient.UnixSocketClientProviderStrategy from ~/.testcontainers.properties, will try it first
17:15:41.430 [main] DEBUG org.testcontainers.dockerclient.DockerClientProviderStrategy - Trying out strategy: UnixSocketClientProviderStrategy
17:15:41.575 [ducttape-0] DEBUG org.testcontainers.dockerclient.DockerClientProviderStrategy - Pinging docker daemon...
17:15:41.585 [ducttape-0] DEBUG org.testcontainers.shaded.com.github.dockerjava.core.command.AbstrDockerCmd - Cmd: 
17:15:41.595 [ducttape-0] DEBUG com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.InternalHttpClient - ex-00000001: preparing request execution
17:15:41.597 [ducttape-0] DEBUG com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.protocol.RequestAddCookies - Cookie spec selected: strict
17:15:41.598 [ducttape-0] DEBUG com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.protocol.RequestAuthCache - Auth cache not set in the context
17:15:41.598 [ducttape-0] DEBUG com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.ProtocolExec - ex-00000001: target auth state: UNCHALLENGED
17:15:41.599 [ducttape-0] DEBUG com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.ProtocolExec - ex-00000001: proxy auth state: UNCHALLENGED
17:15:41.599 [ducttape-0] DEBUG com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.ConnectExec - ex-00000001: acquiring connection with route {}->unix://localhost:2375
17:15:41.599 [ducttape-0] DEBUG com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.InternalHttpClient - ex-00000001: acquiring endpoint (3 MINUTES)
17:15:41.599 [ducttape-0] DEBUG com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager - ex-00000001: endpoint lease request (3 MINUTES) [route: {}->unix://localhost:2375][total available: 0; route allocated: 0 of 2147483647; total allocated: 0 of 2147483647]
17:15:41.601 [ducttape-0] DEBUG com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager - ex-00000001: endpoint leased [route: {}->unix://localhost:2375][total available: 0; route allocated: 1 of 2147483647; total allocated: 1 of 2147483647]
17:15:41.605 [ducttape-0] DEBUG com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager - ex-00000001: acquired ep-00000000
17:15:41.605 [ducttape-0] DEBUG com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.InternalHttpClient - ex-00000001: acquired endpoint ep-00000000
17:15:41.605 [ducttape-0] DEBUG com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.ConnectExec - ex-00000001: opening connection {}->unix://localhost:2375
17:15:41.605 [ducttape-0] DEBUG com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.InternalHttpClient - ep-00000000: connecting endpoint (3 MINUTES)
17:15:41.606 [ducttape-0] DEBUG com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager - ep-00000000: connecting endpoint to unix://localhost:2375 (3 MINUTES)
17:15:41.615 [main] DEBUG org.testcontainers.dockerclient.DockerClientProviderStrategy - UnixSocketClientProviderStrategy: failed with exception RuntimeException (java.lang.UnsatisfiedLinkError: /private/var/folders/fk/89nf61jd7dvb__ls49mj2q680000gp/T/jna--1700769283/jna11940079618175027996.tmp: dlopen(/private/var/folders/fk/89nf61jd7dvb__ls49mj2q680000gp/T/jna--1700769283/jna11940079618175027996.tmp, 0x0001): tried: '/private/var/folders/fk/89nf61jd7dvb__ls49mj2q680000gp/T/jna--1700769283/jna11940079618175027996.tmp' (fat file, but missing compatible architecture (have 'i386,x86_64', need 'arm64e')), '/usr/lib/jna11940079618175027996.tmp' (no such file)). Root cause UnsatisfiedLinkError (/private/var/folders/fk/89nf61jd7dvb__ls49mj2q680000gp/T/jna--1700769283/jna11940079618175027996.tmp: dlopen(/private/var/folders/fk/89nf61jd7dvb__ls49mj2q680000gp/T/jna--1700769283/jna11940079618175027996.tmp, 0x0001): tried: '/private/var/folders/fk/89nf61jd7dvb__ls49mj2q680000gp/T/jna--1700769283/jna11940079618175027996.tmp' (fat file, but missing compatible architecture (have 'i386,x86_64', need 'arm64e')), '/usr/lib/jna11940079618175027996.tmp' (no such file))
17:15:41.617 [main] INFO org.testcontainers.dockerclient.DockerMachineClientProviderStrategy - docker-machine executable was not found on PATH ([/Users/pankajkumar/.rvm/gems/ruby-2.6.3/bin, /Users/pankajkumar/.rvm/gems/ruby-2.6.3@global/bin, /Users/pankajkumar/.rvm/rubies/ruby-2.6.3/bin, /Users/pankajkumar/.rbenv/shims, /opt/homebrew/bin, /opt/homebrew/sbin, /usr/local/bin, /usr/bin, /bin, /usr/sbin, /sbin, /Users/pankajkumar/.rvm/bin])
17:15:41.617 [main] ERROR org.testcontainers.dockerclient.DockerClientProviderStrategy - Could not find a valid Docker environment. Please check configuration. Attempted configurations were:
17:15:41.617 [main] ERROR org.testcontainers.dockerclient.DockerClientProviderStrategy -     UnixSocketClientProviderStrategy: failed with exception RuntimeException (java.lang.UnsatisfiedLinkError: /private/var/folders/fk/89nf61jd7dvb__ls49mj2q680000gp/T/jna--1700769283/jna11940079618175027996.tmp: dlopen(/private/var/folders/fk/89nf61jd7dvb__ls49mj2q680000gp/T/jna--1700769283/jna11940079618175027996.tmp, 0x0001): tried: '/private/var/folders/fk/89nf61jd7dvb__ls49mj2q680000gp/T/jna--1700769283/jna11940079618175027996.tmp' (fat file, but missing compatible architecture (have 'i386,x86_64', need 'arm64e')), '/usr/lib/jna11940079618175027996.tmp' (no such file)). Root cause UnsatisfiedLinkError (/private/var/folders/fk/89nf61jd7dvb__ls49mj2q680000gp/T/jna--1700769283/jna11940079618175027996.tmp: dlopen(/private/var/folders/fk/89nf61jd7dvb__ls49mj2q680000gp/T/jna--1700769283/jna11940079618175027996.tmp, 0x0001): tried: '/private/var/folders/fk/89nf61jd7dvb__ls49mj2q680000gp/T/jna--1700769283/jna11940079618175027996.tmp' (fat file, but missing compatible architecture (have 'i386,x86_64', need 'arm64e')), '/usr/lib/jna11940079618175027996.tmp' (no such file))
17:15:41.617 [main] ERROR org.testcontainers.dockerclient.DockerClientProviderStrategy - As no valid configuration was found, execution cannot continue
17:15:41.618 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - After test class: context [DefaultTestContext@1d7f7be7 testClass = ListingUpdateBatchContainerTest, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration@42f3156d testClass = ListingUpdateBatchContainerTest, locations = '{}', classes = '{class com.housing.cron.CronApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.test.context.support.DynamicPropertiesContextCustomizer@46eedc3b, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@6c2ed0cd, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@51133c06, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@5a3bc7ed, org.springframework.boot.test.web.reactive.server.WebTestClientContextCustomizer@4671115f, org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@46b61c56, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@68df9280, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@f2f2cc1], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map[[empty]]], class annotated with @DirtiesContext [false] with mode [null].

Test ignored.

java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configuration

第一个项目 pom.xml

4.0.0 org.springframework.boot spring-boot-starter-父级 2.5.3 com.jetbrains 测试容器演示 0.0.1-快照 测试容器演示 Spring Boot 的演示项目 11 org.springframework.boot spring-boot-启动器-web

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>42.3.2</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.22</version>
        <scope>provided</scope>
    </dependency>


    <dependency>
        <groupId>org.testcontainers</groupId>
        <artifactId>testcontainers</artifactId>
        <version>1.16.3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.testcontainers</groupId>
        <artifactId>junit-jupiter</artifactId>
        <version>1.16.3</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.testcontainers</groupId>
        <artifactId>postgresql</artifactId>
        <version>1.16.3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.aerospike</groupId>
        <artifactId>spring-data-aerospike</artifactId>
        <version>2.3.3.RELEASE</version>
    </dependency>



</dependencies>



<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
docker testcontainers testcontainers-junit5
4个回答
7
投票

这是 M1 和 Docker 的一个已知问题已通过 Testcontainers 1.15.3 解决。

它适用于您的虚拟项目而不适用于您的遗留项目的原因是您的遗留项目中的某些内容覆盖了

jna

 依赖项。

尝试运行

mvn dependency:tree

 以查看哪个依赖项可传递拉取 
jna

要解决此问题,可以从拉取它的依赖项中使用

<exclude>

 
jna
,或者使用以下命令强制执行 
jna
 >= 5.7.0 的依赖项解析:

<dependencyManagement> <dependencies> <dependency> <groupId>net.java.dev.jna</groupId> <artifactId>jna</artifactId> <version>5.8.0</version> </dependency> </dependencies> </dependencyManagement>
    

3
投票
我也有类似的问题,但事实证明这是因为我使用的是科利马。这篇文章为我指明了正确的方向:

https://www.rockyourcode.com/testcontainers-with-colima/

我只需要设置这些变量: 导出 TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock 导出 DOCKER_HOST="unix://${HOME}/.colima/docker.sock"


2
投票
将TestContainers升级到

1.15.3

后,问题解决了,谢谢。


0
投票
我的版本 1.19.7 有同样的问题,是因为我使用 sudo 来运行 docker 吗?

© www.soinside.com 2019 - 2024. All rights reserved.