在intellij中使用sudo运行Java测试

时间:2019-07-10 20:33:21

标签: java docker intellij-idea testcontainers

上下文

我刚刚找到了testContainers这个可以启动docker容器的库,我想在Intellij内编写一个简单的测试来对其进行测试。

问题

问题在于,当我在Intellij中运行配置时,代码会引发异常,因为运行docker指令需要sudo权限。

23:18:52.180 [main] DEBUG org.testcontainers.dockerclient.DockerClientProviderStrategy - EnvironmentAndSystemPropertyClientProviderStrategy: failed with exception InvalidConfigurationException (ping failed)
23:18:52.186 [main] DEBUG org.testcontainers.dockerclient.DockerClientProviderStrategy - UnixSocketClientProviderStrategy: failed with exception InvalidConfigurationException (ping failed). Root cause NoSuchFileException (/var/run/docker.sock)
23:18:52.187 [main] ERROR org.testcontainers.dockerclient.DockerClientProviderStrategy - Could not find a valid Docker environment. Please check configuration. Attempted configurations were:
23:18:52.187 [main] ERROR org.testcontainers.dockerclient.DockerClientProviderStrategy -     EnvironmentAndSystemPropertyClientProviderStrategy: failed with exception InvalidConfigurationException (ping failed)
23:18:52.187 [main] ERROR org.testcontainers.dockerclient.DockerClientProviderStrategy -     EnvironmentAndSystemPropertyClientProviderStrategy: failed with exception InvalidConfigurationException (ping failed)
23:18:52.187 [main] ERROR org.testcontainers.dockerclient.DockerClientProviderStrategy -     UnixSocketClientProviderStrategy: failed with exception InvalidConfigurationException (ping failed). Root cause NoSuchFileException (/var/run/docker.sock)

试图将当前用户添加到Docker组 sudo usermod -aG docker $USER 即使我使用sudo启动它,我仍然无法在Intellij中运行该应用程序。

替代方法

在有pom的地方直接使用sudo mvn test

问题:

我可以在Intellij中使用它吗?

0 个答案:

没有答案