ContainerLaunchException:中止尝试链接到容器

问题描述 投票:0回答:1

我已经编写了一个使用 TestContainers 的模拟容器的功能测试。

当我使用

./gradlew clean build
运行完整的应用程序测试时,错误仍然出现在控制台中,但仅出现一次(我相信在执行第一次功能测试之前),但它不会使我的任何测试失败。但是,当我单独运行它们时,我看到一些功能测试因此错误而失败。

为了简单起见,我创建了如下简单测试:

示例E2ETest.java:

@MicronautTest(transactional = false)
@ExtendWith(MockitoExtension.class)
public class SampleE2ETest extends ContainerBaseTest {
    @Test
    void sampleTest() {
        assertThat("sadas").isEqualTo("asa");
    }

}

ContainerBaseTest.java

@Testcontainers
@Tag("integration")
@Tag("docker")
@Slf4j
public abstract class ContainerBaseTest {

    static DockerComposeContainer CONTAINER;

    public ContainerBaseTest() {
        if (CONTAINER == null) {
            final WaitStrategy waitStrategy = Wait.forListeningPort().withStartupTimeout(Duration.ofMinutes(2));
            Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(log);

            log.info("Starting testcontainers...");

            CONTAINER = new DockerComposeContainer(new File("docker-compose.yml"))
                    // Without cron
                    .withExposedService("app1_1", 2929, waitStrategy).withLogConsumer("app1_1",logConsumer)
                    .withExposedService("app2_1", 8065, waitStrategy).withLogConsumer("app2_1",logConsumer)
                    .withExposedService("app3_1", 8090, waitStrategy).withLogConsumer("app3_1",logConsumer)
                    .withExposedService("app4_1", 9339, waitStrategy).withLogConsumer("app4_1",logConsumer)
                    .withExposedService("app5_1", 2222, waitStrategy).withLogConsumer("app5_1",logConsumer)
                    .withExposedService("app6_1", 18080, waitStrategy).withLogConsumer("app6_1",logConsumer)
                    .withExposedService("app7_1", 9090, waitStrategy).withLogConsumer("app7_1",logConsumer)
                    .withLocalCompose(true);

            CONTAINER.start();
            log.info("testcontainers started.");
        }
    }
}

上述测试失败并出现以下错误:

18:01:38.913 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app4-1  Creating  
18:01:38.914 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app6-1  Creating  
18:01:38.914 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app1-1  Creating  
18:01:38.914 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app3-1  Creating  
18:01:38.914 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app7-1  Creating  
18:01:38.914 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app5-1  Creating  
18:01:38.915 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-cron-1  Creating  
18:01:38.915 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app2-1  Creating  
18:01:39.002 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-cron-1  Created  
18:01:39.006 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app6-1  Created  
18:01:39.007 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app7-1  Created  
18:01:39.009 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app2-1  Created  
18:01:39.011 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app4-1  Created  
18:01:39.014 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app1-1  Created  
18:01:39.017 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app5-1  Created  
18:01:39.017 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app3-1  Created  
18:01:39.022 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app1-1  Starting  
18:01:39.023 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app7-1  Starting  
18:01:39.024 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-cron-1  Starting  
18:01:39.024 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app2-1  Starting  
18:01:39.025 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app5-1  Starting  
18:01:39.027 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app6-1  Starting  
18:01:39.028 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app4-1  Starting  
18:01:39.029 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app3-1  Starting  
18:01:39.546 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-cron-1  Started  
18:01:39.637 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app1-1  Started  
18:01:39.746 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app3-1  Started  
18:01:39.908 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app2-1  Started  
18:01:39.914 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app6-1  Started  
18:01:39.955 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app7-1  Started  
18:01:40.010 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app5-1  Started  
18:01:40.030 [Thread-9] INFO  🐳 [docker-compose] - Container k5bii89amzd5-app4-1  Started  
18:01:40.044 [Test worker] DEBUG o.t.s.o.z.exec.WaitForProcess - Process[pid=45511, exitValue=0] stopped with exit code 0  
18:01:40.046 [Test worker] INFO  🐳 [docker-compose] - Docker Compose has finished running  
18:01:40.050 [Test worker] DEBUG o.t.u.PrefixingImageNameSubstitutor - No prefix is configured  
18:01:40.051 [Test worker] DEBUG o.t.utility.ImageNameSubstitutor - Did not find a substitute image for alpine/socat:1.7.3.4-r0 (using image substitutor: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor'))  
18:01:40.054 [Test worker] DEBUG o.t.s.c.g.d.c.command.AbstrDockerCmd - Cmd: ListImagesCmdImpl[imageNameFilter=<null>,showAll=false,filters=org.testcontainers.shaded.com.github.dockerjava.core.util.FiltersBuilder@0]  
18:01:40.203 [Test worker] DEBUG o.t.images.AbstractImagePullPolicy - Using locally available and not pulling image: alpine/socat:1.7.3.4-r0  
18:01:40.204 [Test worker] DEBUG 🐳 [alpine/socat:1.7.3.4-r0] - Starting container: alpine/socat:1.7.3.4-r0  
18:01:40.204 [Test worker] DEBUG 🐳 [alpine/socat:1.7.3.4-r0] - Trying to start container: alpine/socat:1.7.3.4-r0 (attempt 1/1)  
18:01:40.205 [Test worker] DEBUG 🐳 [alpine/socat:1.7.3.4-r0] - Starting container: alpine/socat:1.7.3.4-r0  
18:01:40.205 [Test worker] INFO  🐳 [alpine/socat:1.7.3.4-r0] - Creating container for image: alpine/socat:1.7.3.4-r0  
18:01:40.205 [Test worker] DEBUG o.t.utility.RegistryAuthLocator - Looking up auth config for image: alpine/socat:1.7.3.4-r0 at registry: index.docker.io  
18:01:40.206 [Test worker] DEBUG o.t.utility.RegistryAuthLocator - No matching Auth Configs - falling back to defaultAuthConfig [null]  
18:01:40.206 [Test worker] DEBUG o.t.d.AuthDelegatingDockerClientConfig - Effective auth config [null]  
18:01:40.211 [Test worker] DEBUG o.t.s.c.g.d.c.command.AbstrDockerCmd - Cmd: -1,<null>,false,<null>,<null>,org.testcontainers.shaded.com.github.dockerjava.core.util.FiltersBuilder@96a2da2c  
18:01:40.244 [Test worker] ERROR 🐳 [alpine/socat:1.7.3.4-r0] - Could not start container  
org.testcontainers.containers.ContainerLaunchException: Aborting attempt to link to container k5bii89amzd5_app7_1 as it is not running
    at org.testcontainers.containers.GenericContainer.applyConfiguration(GenericContainer.java:779)
    at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:359)
    at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:325)
    at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
    at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:323)

Container startup failed
org.testcontainers.containers.ContainerLaunchException: Container startup failed
    at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:330)
    at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:311)
    at org.testcontainers.containers.DockerComposeContainer.startAmbassadorContainers(DockerComposeContainer.java:331)
    at org.testcontainers.containers.DockerComposeContainer.start(DockerComposeContainer.java:178)
Caused by: org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception
    at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:88)
    at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:323)
    ... 96 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
    at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:497)
    at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:325)
    at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
    ... 97 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Aborting attempt to link to container k5bii89amzd5_app7_1 as it is not running
    at org.testcontainers.containers.GenericContainer.applyConfiguration(GenericContainer.java:779)
    at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:359)

gradle 文件中的 TestContainer 和 Junit 依赖项

testImplementation("io.micronaut.test:micronaut-test-junit5")
testImplementation("org.junit.jupiter:junit-jupiter-api")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testImplementation("org.testcontainers:testcontainers:1.15.2")
testImplementation("org.testcontainers:junit-jupiter:1.15.2")
testImplementation("org.junit.jupiter:junit-jupiter-params")
docker gradle junit e2e-testing testcontainers
1个回答
0
投票

不确定为什么它不能与 DockerComposeContainer 一起使用,但从 DockerComposeContainer 迁移到 ComposeContainer 似乎已经解决了这个问题。

https://github.com/testcontainers/testcontainers-java/issues/7644

https://java.testcontainers.org/modules/docker_compose/#compose-v2

© www.soinside.com 2019 - 2024. All rights reserved.