Elasticsearch 无法与 Docker 一起运行



我写了一些与Elasticsearch集成的代码,当ES在我的计算机上运行时,它运行流畅。但是,当我尝试通过Docker运行ES时,我一次又一次地收到此错误:

org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{hrmyFR97S_qMsPEsOOEFjw}{localhost}{127.0.0.1:9300}]

这是我初始化客户端的方式:

Settings settings = Settings.builder()
                .put("cluster.name", "elasticsearch123")
                .build();
 Client client = new PreBuiltTransportClient(settings)
                    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));

这就是我的 docker 撰写文件的样子:

version: '2'
services:
      elastic3:
        image: docker.elastic.co/elasticsearch/elasticsearch:5.4.0
        environment:
          - cluster.name=elasticsearch123
          - bootstrap.memory_lock=true
          - transport.host=127.0.0.1
          - xpack.security.enabled=false
          - http.host=0.0.0.0
          - network.host=127.0.0.1
        ports:
          - "9200:9200"
          - "9300:9300"
        volumes:
         - /usr/share/elasticsearch/data

这是我的依赖项:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>1.5.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>5.4.0</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>transport</artifactId>
        <version>5.4.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.7</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.7</version>
    </dependency>
</dependencies>`

有什么想法吗?我真的没有想法了!

我敢打赌,这完全与错误的网络配置有关。检查网络操作模式,并使用默认bridge host。此外,您无需"暴露"prots,因为所有端口都将开箱即用。这是因为 docker 容器将直接绑定虚拟接口的接口。

检查Network settings部分

https://docs.docker.com/engine/reference/run/#container-identification

当您在这里使用compose时,您有正确的配置选项

https://docs.docker.com/compose/compose-file/#networkmode

相关内容

  • 没有找到相关文章

最新更新