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

有任何想法吗? 我真的没有想法了!

我敢打赌,这是关于错误的networkingconfiguration。 检查networking运行模式,并使用默认bridge host 。 此外,您不需要“暴露”保护者,因为所有的端口将被暴露在外。 这是因为docker容器将直接绑定你虚拟的虚拟界面。

检查Network settings部分

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

正如你在这里使用compose你有适当的configuration选项

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