elasticsearch,spring-boot-maven-plugin,testcontainers,Java,Docker,elasticsearch,Spring Boot Maven Plugin,Testcontainers" /> elasticsearch,spring-boot-maven-plugin,testcontainers,Java,Docker,elasticsearch,Spring Boot Maven Plugin,Testcontainers" />

Java Testcontainers在等待容器端口打开时超时,带有Elasticsearch docker图像

Java Testcontainers在等待容器端口打开时超时,带有Elasticsearch docker图像,java,docker,elasticsearch,spring-boot-maven-plugin,testcontainers,Java,Docker,elasticsearch,Spring Boot Maven Plugin,Testcontainers,我正在学习SpringDataElasticSearch和Testcontainers。作为第一步,我尝试使用Testcontainers运行Elasticsearch的docker映像,但我只花了一整天的时间,却无法让它工作 下面是测试类主体: import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.testcontainers.containers.GenericConta

我正在学习SpringDataElasticSearch和Testcontainers。作为第一步,我尝试使用Testcontainers运行Elasticsearch的docker映像,但我只花了一整天的时间,却无法让它工作

下面是测试类主体:


import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;

@Testcontainers
public class TestcontainersTest {
    // container {
    @Container
    public GenericContainer container = new GenericContainer(DockerImageName.parse("elasticsearch:7.6.2"))
            .withExposedPorts(9200)
            .withCommand("--name=esTest -e \"discovery.type=single-node\"");
//    public GenericContainer container = new GenericContainer(DockerImageName.parse("redis:5.0.3-alpine"))
//            .withExposedPorts(6379);

    @BeforeEach
    public void setUp() {
        String address = container.getHost();
        Integer port = container.getFirstMappedPort();

        // Now we have an address and port for Redis, no matter where it is running
//        underTest = new RedisBackedCache(address, port);
    }

    @Test
    public void testTest() {
        while (true);
    }
}
我在
setUp()
testTest()
中为每一行设置断点,但是当我使用
Debug testTest()
运行时,它永远不会到达行。(我正在使用IntelliJ IDEA btw)如果我的理解是正确的,它只是在启动docker容器时失败了

另一方面,如果我在
设置
之前更改注释掉的部分,也就是说,如果我更改为使用redis图像(作为官方Testcontainers网页中的代码),事情会顺利进行,我可以在断点处停下来,检查容器是否使用
docker ps
运行:

$ docker ps
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS              PORTS                     NAMES
0db5ae6e1129        redis:5.0.3-alpine          "docker-entrypoint.s…"   7 seconds ago       Up 6 seconds        0.0.0.0:32817->6379/tcp   wizardly_euler
31620f900e18        testcontainers/ryuk:0.3.0   "/app"                   8 seconds ago       Up 7 seconds        0.0.0.0:32816->8080/tcp   testcontainers-ryuk-e84d6102-4e8c-4c80-bfc7-5deb55864526
我试图深入研究Elasticsearch容器尝试后产生的错误消息。它很长,我从中发现如下:

18:09:03.133 [ducttape-0] DEBUG org.testcontainers.containers.ExecInContainerPattern - /determined_brown: Running "exec" command: /bin/sh -c true &&  (cat /proc/net/tcp* | awk '{print $2}' | grep -i ':0*23f0' || nc -vz -w 1 localhost 9200 || /bin/bash -c '</dev/tcp/localhost/9200')
18:09:03.133 [ducttape-0] DEBUG org.testcontainers.shaded.com.github.dockerjava.core.command.AbstrDockerCmd - Cmd: 2cb002a7b520fe9b2f5771088e028b34bf4b58bb041a3d6abb5e200cf4c1fc6e,<null>,true,true,<null>,<null>,<null>,{/bin/sh,-c,true &&  (cat /proc/net/tcp* | awk '{print $2}' | grep -i ':0*23f0' || nc -vz -w 1 localhost 9200 || /bin/bash -c '</dev/tcp/localhost/9200')},<null>,<null>
18:09:04.153 [ducttape-0] DEBUG org.testcontainers.containers.ExecInContainerPattern - /determined_brown: Running "exec" command: /bin/sh -c true &&  (cat /proc/net/tcp* | awk '{print $2}' | grep -i ':0*23f0' || nc -vz -w 1 localhost 9200 || /bin/bash -c '</dev/tcp/localhost/9200')
18:09:04.153 [ducttape-0] DEBUG org.testcontainers.shaded.com.github.dockerjava.core.command.AbstrDockerCmd - Cmd: 2cb002a7b520fe9b2f5771088e028b34bf4b58bb041a3d6abb5e200cf4c1fc6e,<null>,true,true,<null>,<null>,<null>,{/bin/sh,-c,true &&  (cat /proc/net/tcp* | awk '{print $2}' | grep -i ':0*23f0' || nc -vz -w 1 localhost 9200 || /bin/bash -c '</dev/tcp/localhost/9200')},<null>,<null>
18:09:05.162 [ducttape-0] DEBUG org.testcontainers.containers.ExecInContainerPattern - /determined_brown: Running "exec" command: /bin/sh -c true &&  (cat /proc/net/tcp* | awk '{print $2}' | grep -i ':0*23f0' || nc -vz -w 1 localhost 9200 || /bin/bash -c '</dev/tcp/localhost/9200')
18:09:05.163 [ducttape-0] DEBUG org.testcontainers.shaded.com.github.dockerjava.core.command.AbstrDockerCmd - Cmd: 2cb002a7b520fe9b2f5771088e028b34bf4b58bb041a3d6abb5e200cf4c1fc6e,<null>,true,true,<null>,<null>,<null>,{/bin/sh,-c,true &&  (cat /proc/net/tcp* | awk '{print $2}' | grep -i ':0*23f0' || nc -vz -w 1 localhost 9200 || /bin/bash -c '</dev/tcp/localhost/9200')},<null>,<null>
18:09:03.133[ducttape-0]DEBUG org.testcontainers.containers.ExecInContainerPattern-/determined\u brown:运行“exec”命令:/bin/sh-c true&(cat/proc/net/tcp*| awk'{print$2}'| grep-i':0*23f0'| nc-vz-w 1 localhost 9200| |/bin/bash-c'尝试更改:

DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:7.6.2")

虽然前者应该重定向到后者

编辑:问题已通过使用?

尝试更改解决:

DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:7.6.2")

虽然前者应该重定向到后者


编辑:该问题已通过使用解决?

您是否已修复或仍需要帮助?谢谢您,是的,切换到Elasticsearch模块后我的问题已解决(谢谢dadoonet!)您是否已修复或仍需帮助?谢谢您,是的,切换到Elasticsearch模块后我的问题已解决(谢谢达杜内特!)唯一的原因是我没有注意到Elasticsearch有这样一个特定的模块。谢谢你让我知道!这个简单的更改仍然不能使GenericContainer与Elasticsearch图像一起工作。你是否尝试在Elasticsearch启动时读取日志?可能在超时之前启动它没有完成?可能,但我的问题解决了切换到Elasticsearch模块后的ves(谢谢!),所以我放弃用这种方式进一步挖掘…唯一的原因是我没有注意到Elasticsearch有这样一个特定的模块。谢谢你让我知道!这个简单的更改仍然不能使GenericContainer与Elasticsearch图像一起工作。你是否尝试在Elasticsearch启动时读取它的日志?可能是在或者超时?也许吧,但我的问题在切换到Elasticsearch模块后解决了(谢谢!),所以我放弃了用这种方式进一步挖掘。。。