如何解决在使用Testcontainers与Quarkus时出现“找不到有效的Docker环境”错误?

huangapple go评论67阅读模式
英文:

How can I resolve the 'Could not find a valid Docker environment' error when using Testcontainers with Quarkus?

问题

我尝试在Quarkus(v2.16.4.Final,java:Amazon Corretto 17)应用程序的测试中使用Testcontainers(v1.18.0)。当我启动它时,我收到以下堆栈跟踪:

2023-06-01 13:11:10,326 INFO  [org.tes.uti.ImageNameSubstitutor] (main) 图像名称替换将由:DefaultImageNameSubstitutor执行(由'ConfigurationFileImageNameSubstitutor'和'PrefixingImageNameSubstitutor'组合而成)
2023-06-01 13:11:10,502 INFO  [org.tes.doc.DockerClientProviderStrategy] (pool-3-thread-1) 从~/.testcontainers.properties加载org.testcontainers.dockerclient.NpipeSocketClientProviderStrategy,将首先尝试它
2023-06-01 13:11:10,599 INFO  [org.tes.doc.DockerMachineClientProviderStrategy] (pool-3-thread-1) 未在PATH上找到docker-machine可执行文件([C:\Python311\Scripts\,C:\Python311\,C:\Program Files(x86)\Microsoft SDKs\Azure\CLI2\wbin,C:\WINDOWS\system32,C:\WINDOWS,C:\WINDOWS\System32\Wbem,C:\WINDOWS\System32\WindowsPowerShell\v1.0\,C:\WINDOWS\System32\OpenSSH\,C:\ProgramData\chocolatey\bin,C:\Program Files\Azure Data Studio\bin,C:\Program Files\Microsoft\Azure Functions Core Tools\,C:\Program Files\PuTTY\,C:\Program Files\TortoiseGit\bin,C:\Program Files\Java\jdk17.0.4_8\bin,C:\Program Files\Java\scripts,C:\Program Files\nodejs\,C:\Program Files\dotnet\,C:\Program Files\TortoiseSVN\bin,C:\Program Files\Git\cmd,C:\Program Files\Maven\apache-maven-3.8.6\bin,,C:\Program Files\Docker\Docker\resources\bin,C:\Users\***\AppData\Local\Microsoft\WindowsApps,C:\Program Files\Azure Data Studio\bin,C:\Users\***\AppData\Local\Programs\Microsoft VS Code\bin,C:\Users\***\AppData\Roaming\npm,C:\Program Files\Java\jdk11.0.16_8\bin,C:\Users\***\.dotnet\tools,C:\Users\***\AppData\Local\JetBrains\Toolbox\scripts,C:\Users\***\.azure-kubelogin,C:\Users\***\AppData\Local\Microsoft\WindowsApps,C:\Program Files\Docker\Docker\resources\bin])
2023-06-01 13:11:10,601 ERROR [org.tes.doc.DockerClientProviderStrategy] (pool-3-thread-1) 未找到有效的Docker环境。请检查配置。尝试的配置为:
    NpipeSocketClientProviderStrategy:出现NoClassDefFoundError异常(com/github/dockerjava/api/command/LoadImageAsyncCmd)。根本原因ClassNotFoundException(com.github.dockerjava.api.command.LoadImageAsyncCmd)未找到有效的配置,无法继续执行。
有关更多详细信息,请参见https://www.testcontainers.org/on_failure.html。

java.lang.RuntimeException:java.lang.reflect.InvocationTargetException

在io.quarkus.test.junit.QuarkusTestExtension.throwBootFailureException(QuarkusTestExtension.java:625)处
在io.quarkus.test.junit.QuarkusTestExtension.interceptTestClassConstructor(QuarkusTestExtension.java:696)处
在org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)处
在org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)处
在org.junit.jupiter.api.extension.InvocationInterceptor.interceptTestClassConstructor(InvocationInterceptor.java:73)处
在org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)处
在org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)处
在org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)处
在org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)处
在org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)处
在org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)处
在org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:62)处
在org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeTestClassConstructor(ClassBasedTestDescriptor.java:363)处
在org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.instantiateTestClass(ClassBasedTestDescriptor.java:310)处
在org.junit.jupiter.engine.descriptor.ClassTestDescriptor.instantiateTestClass(ClassTestDescriptor.java:79)处
在org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.instantiateAndPostProcessTestInstance(ClassBasedTestDescriptor.java:286)处
在org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$4(ClassBasedTestDescriptor.java:278)处
在java.base/java.util.Optional.orElseGet(Optional.java:364)处
在org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$5(ClassBasedTestDescriptor.java:277)处
在org.junit.jupiter.engine.execution.TestInstancesProvider.getTestInstances(TestInstancesProvider.java:31)处
在org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$prepare$0(TestMethodTestDescriptor.java:105)处
在org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)处
在org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:104)处
在org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:68)处
在org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$prepare$2(NodeTestTask.java:123)处
在org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)处
在org.junit.platform.engine.support.hierarchical.NodeTestTask.prepare(NodeTestTask.java:123)处
在org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:90)处
在java.base/java.util.ArrayList.forEach(ArrayList.java:1511)处
在org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)处
在org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(

<details>
<summary>英文:</summary>

I try to use Testcontainers (v1.18.0) for tests in a Quarkus (v2.16.4.Final, java: Amazon Corretto 17) application. When I start it up I get the following stack trace:


2023-06-01 13:11:10,326 INFO [org.tes.uti.ImageNameSubstitutor] (main) Image name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor')
2023-06-01 13:11:10,502 INFO [org.tes.doc.DockerClientProviderStrategy] (pool-3-thread-1) Loaded org.testcontainers.dockerclient.NpipeSocketClientProviderStrategy from ~/.testcontainers.properties, will try it first
2023-06-01 13:11:10,599 INFO [org.tes.doc.DockerMachineClientProviderStrategy] (pool-3-thread-1) docker-machine executable was not found on PATH ([C:\Python311\Scripts, C:\Python311, C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin, C:\WINDOWS\system32, C:\WINDOWS, C:\WINDOWS\System32\Wbem, C:\WINDOWS\System32\WindowsPowerShell\v1.0, C:\WINDOWS\System32\OpenSSH, C:\ProgramData\chocolatey\bin, C:\Program Files\Azure Data Studio\bin, C:\Program Files\Microsoft\Azure Functions Core Tools, C:\Program Files\PuTTY, C:\Program Files\TortoiseGit\bin, C:\Program Files\Java\jdk17.0.4_8\bin, C:\Program Files\Java\scripts, C:\Program Files\nodejs, C:\Program Files\dotnet, C:\Program Files\TortoiseSVN\bin, C:\Program Files\Git\cmd, C:\Program Files\Maven\apache-maven-3.8.6\bin, , C:\Program Files\Docker\Docker\resources\bin, C:\Users*\AppData\Local\Microsoft\WindowsApps, C:\Program Files\Azure Data Studio\bin, C:\Users*\AppData\Local\Programs\Microsoft VS Code\bin, C:\Users*\AppData\Roaming\npm, C:\Program Files\Java\jdk11.0.16_8\bin, C:\Users*.dotnet\tools, C:\Users*\AppData\Local\JetBrains\Toolbox\scripts, C:\Users*.azure-kubelogin, C:\Users***\AppData\Local\Microsoft\WindowsApps, C:\Program Files\Docker\Docker\resources\bin])
2023-06-01 13:11:10,601 ERROR [org.tes.doc.DockerClientProviderStrategy] (pool-3-thread-1) Could not find a valid Docker environment. Please check configuration. Attempted configurations were:
NpipeSocketClientProviderStrategy: failed with exception NoClassDefFoundError (com/github/dockerjava/api/command/LoadImageAsyncCmd). Root cause ClassNotFoundException (com.github.dockerjava.api.command.LoadImageAsyncCmd)As no valid configuration was found, execution cannot continue.
See https://www.testcontainers.org/on_failure.html for more details.

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException

at io.quarkus.test.junit.QuarkusTestExtension.throwBootFailureException(QuarkusTestExtension.java:625)
at io.quarkus.test.junit.QuarkusTestExtension.interceptTestClassConstructor(QuarkusTestExtension.java:696)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at org.junit.jupiter.api.extension.InvocationInterceptor.interceptTestClassConstructor(InvocationInterceptor.java:73)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:62)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeTestClassConstructor(ClassBasedTestDescriptor.java:363)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.instantiateTestClass(ClassBasedTestDescriptor.java:310)
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.instantiateTestClass(ClassTestDescriptor.java:79)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.instantiateAndPostProcessTestInstance(ClassBasedTestDescriptor.java:286)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$4(ClassBasedTestDescriptor.java:278)
at java.base/java.util.Optional.orElseGet(Optional.java:364)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$5(ClassBasedTestDescriptor.java:277)
at org.junit.jupiter.engine.execution.TestInstancesProvider.getTestInstances(TestInstancesProvider.java:31)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$prepare$0(TestMethodTestDescriptor.java:105)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:104)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:68)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$prepare$2(NodeTestTask.java:123)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.prepare(NodeTestTask.java:123)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:90)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:147)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:127)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:90)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:55)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:102)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:54)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)

Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at io.quarkus.test.junit.QuarkusTestExtension.doJavaStart(QuarkusTestExtension.java:237)
at io.quarkus.test.junit.QuarkusTestExtension.ensureStarted(QuarkusTestExtension.java:592)
at io.quarkus.test.junit.QuarkusTestExtension.beforeAll(QuarkusTestExtension.java:640)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeBeforeAllCallbacks$12(ClassBasedTestDescriptor.java:395)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeBeforeAllCallbacks(ClassBasedTestDescriptor.java:395)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:211)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:84)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:148)
... 36 more
Caused by: java.util.concurrent.CompletionException: java.lang.RuntimeException: Unable to start Quarkus test resource class com..locref.DatabaseResource
at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315)
at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320)
at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1807)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.RuntimeException: Unable to start Quarkus test resource class com.
.locref.DatabaseResource
at io.quarkus.test.common.TestResourceManager$TestResourceEntryRunnable.run(TestResourceManager.java:487)
at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804)
... 3 more
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:256)
at java.base/java.util.Optional.orElseThrow(Optional.java:403)
at org.testcontainers.dockerclient.DockerClientProviderStrategy.getFirstValidStrategy(DockerClientProviderStrategy.java:247)
at org.testcontainers.DockerClientFactory.getOrInitializeStrategy(DockerClientFactory.java:150)
at org.testcontainers.DockerClientFactory.client(DockerClientFactory.java:186)
at org.testcontainers.DockerClientFactory$1.getDockerClient(DockerClientFactory.java:104)
at com.github.dockerjava.api.DockerClientDelegate.authConfig(DockerClientDelegate.java:108)
at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:321)
at com.***.locref.DatabaseResource.start(DatabaseResource.java:28)
at io.quarkus.test.common.TestResourceManager$TestResourceEntryRunnable.run(TestResourceManager.java:481)
... 4 more


I have a class that implements `QuarkusTestResourceLifecycleManager` and starts a `PostgreSQLContainer`. I add it to a Test class annotated with `@QuarkusTest` and `@QuarkusTestResource`. 

I used a very similar setup in a plain Java application without any problems. Problems only arise when Quarkus appears in the loop. I researched all exceptions related to the docker runtime and the NpipeSocketClientProviderStrategy but was not able to find a solution.

</details>


# 答案1
**得分**: 2

在升级 Quarkus 中的 Testcontainers 时,您还需要检查 docker-java 版本。保持这些版本的一致性不应引起任何问题。

Quarkus 对此有一条注释,可以参考 https://github.com/quarkusio/quarkus/blob/d87ef55647af0a8b6703e3ada5a6da130b139588/bom/application/pom.xml#L209

<details>
<summary>英文:</summary>

When upgrading Testcontainers in Quarkus, you also need to check the docker-java version. Keeping those versions aligned should not cause any issues.

Quarkus has a comment about it see https://github.com/quarkusio/quarkus/blob/d87ef55647af0a8b6703e3ada5a6da130b139588/bom/application/pom.xml#L209

</details>



# 答案2
**得分**: -1

Quarkus和Testcontainers的版本不兼容。通过Maven的dependencyManagement在quarkus-bom中解决Testcontainers的版本问题,结果是1.17.6,可以正常工作。

<details>
<summary>英文:</summary>

The versions of Quarkus and Testcontainers were incompatible. Resolving the version of Testcontainers via quarkus-bom in maven dependencyManagement resulted in 1.17.6 which works as expected.

</details>



huangapple
  • 本文由 发表于 2023年6月1日 19:49:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76381567.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定