我正在为我的微服务(Java Spring)构建集成测试基础结构。 由于我尝试为测试创建基类,从而导致测试容器出现问题,该类将在容器上启动redis,并用作已测试服务的redis。
抽象测试如下:
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles(Constants.SPRING_PROFILE_DEVELOPMENT)
public class AbstractRedisContainerTest {
@Rule
public GenericContainer redis = new GenericContainer("redis:3.0.6")
.withExposedPorts(6379);
我的日志显示以下失败的消息:
2020-03-04 12:28:55.545 ERROR [myService,,,] 27709 --- [main] o.t.d.DockerClientProviderStrategy:
Could not find a valid Docker environment. Please check configuration. Attempted configurations were:
2020-03-04 12:28:55.546 ERROR [myService,,,] 27709 --- [main] o.t.d.DockerClientProviderStrategy:
EnvironmentAndSystemPropertyClientProviderStrategy:
failed with exception InvalidConfigurationException (ping failed)
2020-03-04 12:28:55.546 ERROR [myService,,,] 27709 --- [main] o.t.d.DockerClientProviderStrategy:EnvironmentAndSystemPropertyClientProviderStrategy:
failed with exception InvalidConfigurationException (ping failed)
2020-03-04 12:28:55.546 ERROR [myService,,,] 27709 --- [main] o.t.d.DockerClientProviderStrategy:UnixSocketClientProviderStrategy:
failed with exception InvalidConfigurationException (ping failed). Root cause LastErrorException ([13])
2020-03-04 12:28:55.546 ERROR [myService,,,] 27709 --- [main] o.t.d.DockerClientProviderStrategy: ProxiedUnixSocketClientProviderStrategy:
failed with exception InvalidConfigurationException (ping failed). Root cause TimeoutException (null)
2020-03-04 12:28:55.546 ERROR [myService,,,] 27709 --- [main] o.t.d.DockerClientProviderStrategy: As no valid configuration was found, execution cannot continue
org.testcontainers.containers.ContainerLaunchException: Container startup failed
这是代码中失败行的错误:
Caused by: org.testcontainers.containers.ContainerFetchException: Can't get Docker image:
RemoteDockerImage(imageNameFuture=java.util.concurrent.CompletableFuture@3186b07d[Completed normally],
imagePullPolicy=DefaultPullPolicy(), dockerClient=LazyDockerClient.INSTANCE)
任何想法如何配置我的环境或这里缺少什么? 重要的是要声明我已经成功在本地运行docker映像(此处也说明了这一点),并且我已经从cli运行了docker环境。我从想法上运行了这个测试。 不知道是否相关,但是我以用户(而不是以root身份)运行它。