Kibana 的端口问题

port issue for Kibana

当ES和Kibana使用默认9200/5601时,ES和Kibana都启动了。

我想按如下方式更改端口。 ES 在 http://localhost:34343/ 启动了,但是 Kibana 不工作。我尝试了服务名称 ELASTICSEARCH_HOSTS=http://elasticsearch:34343 和容器名称 ELASTICSEARCH_HOSTS=http://my_elasticsearch:34343

version: '3.7'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.16.3
    container_name: my_elasticsearch
    environment:
      - "ES_JAVA_OPTS=-Xms1g -Xmx1g"
      - discovery.type=single-node
    ports:
      - 34343:9200

  kibana:
    image: docker.elastic.co/kibana/kibana:7.16.3

    environment:
      - ELASTICSEARCH_HOSTS=http://elasticsearch:34343
    ports:
      - 5666:5601

我收到 Kibana 的错误

"tags":["error","elasticsearch-service"],"pid":8,"message":"Unable to retrieve version information from Elasticsearch nodes. connect ECONNREFUSED 172.18.0.3:34343"}

Tldr;

我相信您的 docker-compose 文件可能有误。 您正在为 Kibana 提供映射到主机 34343 上的端口,而不是服务在 docker 内部网络中监听 9200 的主机。

networking documentation of docker 阅读帮助了我

修复

version: '3.7'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.16.3
    container_name: my_elasticsearch
    environment:
      - "ES_JAVA_OPTS=-Xms1g -Xmx1g"
      - discovery.type=single-node
    ports:
      - 34343:9200

  kibana:
    image: docker.elastic.co/kibana/kibana:7.16.3

    environment:
      # - ELASTICSEARCH_HOSTS=http://elasticsearch: 34343
      - ELASTICSEARCH_HOSTS=http://elasticsearch:9200
    ports:
      - 5666:5601