环境
MacBook
问题
Java代码中使用testcontainers
启动报错
ERROR org.testcontainers.dockerclient.DockerClientProviderStrategy - Could not find a valid Docker environment. Please check configuration. Attempted configurations were:
UnixSocketClientProviderStrategy: failed with exception InvalidConfigurationException (Could not find unix domain socket). Root cause NoSuchFileException (/var/run/docker.sock)As no valid configuration was found, execution cannot continue.
See https://www.testcontainers.org/on_failure.html for more details.
java.util.concurrent.CompletionException: java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configuration
at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:273)
at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:280)
at java.util.concurrent.CompletableFuture.uniRun(CompletableFuture.java:722)
at java.util.concurrent.CompletableFuture$UniRun.tryFire(CompletableFuture.java:701)
at java.util.concurrent.CompletableFuture$Completion.run(CompletableFuture.java:456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:750)
原因
MacBook 在Docker Desktop 4.12版本之后不会默认创建/var/run/docker.sock
解决方法
在Docker Desktop中启用
然后点击Apply & restart
就可以找到这个文件了
mac@MacBook-Pro ~ ls /var/run/docker.sock
/var/run/docker.sock
参考
https://github.com/testcontainers/testcontainers-java/discussions/6045