kna*_*alx 5 containers elasticsearch testcontainers
我尝试使用elasticsearch容器编写测试.我用https://www.testcontainers.org/库运行它.那是我的配置:
@ClassRule
public static GenericContainer elasticContainer =
new GenericContainer("docker.elastic.co/elasticsearch/elasticsearch:5.3.0")
.withExposedPorts(9300, 9200)
.withEnv("xpack.security.enabled", "false")
.withEnv("transport.host", "127.0.0.1")
.withEnv("http.host", "0.0.0.0");
Run Code Online (Sandbox Code Playgroud)
我有一个例外:
org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{9fuJUZYWS6O6IgLGOgJDaA}{localhost}{127.0.0.1:32792}]
Run Code Online (Sandbox Code Playgroud)
我重新配置了我的端口进行测试,并且可以使用9200端口(在testcontainers映射的端口上) - 我通过curl检查了它.但9300不是.
有谁知道如何解决运输主机问题?
问题在于弹性搜索容器 - 而不是testcontainers lib.
我在这里找到了解决方案 https://github.com/olivere/elastic/issues/57#issuecomment-88697714
传输客户端无法解析容器中的ElasticSearch节点.
最终代码是:
@ClassRule
public static GenericContainer elasticContainer =
new FixedHostPortGenericContainer("docker.elastic.co/elasticsearch/elasticsearch:5.3.0")
.withFixedExposedPort(9200, 9200)
.withFixedExposedPort(9300, 9300)
.waitingFor(Wait.forHttp("/")) // Wait until elastic start
.withEnv("xpack.security.enabled", "false")
.withEnv("network.host", "_site_")
.withEnv("network.publish_host", "_local_");
Run Code Online (Sandbox Code Playgroud)
此外,如果你想在docker中启动ElasticSearch并使用9300(传输端口)运行:
docker run -p 9300:9300 -p 9200:9200 -e "xpack.security.enabled=false" -e "network.host=_site_" -e "network.publish_host=_local_" docker.elastic.co/elasticsearch/elasticsearch:5.3.0
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2006 次 |
最近记录: |