Elasticsearch不会与Docker一起运行

时间:2017-05-23 12:03:42

标签: java elasticsearch docker docker-compose elasticsearch-5

我编写了一些与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-compose文件的样子:

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>`

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

1 个答案:

答案 0 :(得分:0)

我打赌这完全是关于错误的网络配置。检查网络操作模式,并使用host保证默认bridge。此外,你不需要&#34;暴露&#34;因为所有端口都将开箱即用。这是因为docker容器会直接绑定你的hots虚拟接口。

检查

中的Network settings部分

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

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

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