我刚刚找到了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中使用它吗?