[英]Kibana on Docker cannot connect to Elasticsearch
I tried to create Kibana and Elasticsearch and it seems that Kibana is having trouble identifying Elasticsearch. 我试图创建Kibana和Elasticsearch,看起来Kibana在识别Elasticsearch时遇到了麻烦。
Here are my steps: 这是我的步骤:
1) Create network 1)创建网络
docker network create mynetwork --driver=bridge
2) Run Elasticsearch Container 2)运行Elasticsearch容器
docker run -d -p 9200:9200 -p 9300:9300 --name elasticsearch_2_4 --network mynetwork elasticsearch:2.4
3) Run Kibana Container 3)运行Kibana容器
docker run -i --network mynetwork -p 5601:5601 kibana:4.6
I get a JSON output when I connect to Elasticsearch via http://localhost:9200/ through my browser. 当我通过http:// localhost:9200 /通过我的浏览器连接到Elasticsearch时,我得到一个JSON输出。
But when I open http://localhost:5601/ I get 但是当我打开http:// localhost:5601 /我得到
Unable to connect to Elasticsearch at http://elasticsearch:9200.
Alternate Approach, 替代方法,
I still get a similar error when I try 我尝试时仍然遇到类似的错误
docker run -d -e ELASTICSEARCH_URL=http://127.0.0.1:9200 -p 5601:5601 kibana:4.6
where I get the error 我得到错误的地方
Unable to connect to Elasticsearch at http://127.0.0.1:9200.
My blog post based on the accepted answer: https://gunith.github.io/docker-kibana-elasticsearch/ 我的博客帖子基于公认的答案: https : //gunith.github.io/docker-kibana-elasticsearch/
There is some misunderstanding about what localhost
or 127.0.0.1
means when running a command inside a container. 关于在容器内运行命令时
localhost
或127.0.0.1
含义存在一些误解。 Because every container has its own networking, localhost
is not your real host system but either the container itself. 因为每个容器都有自己的网络,所以
localhost
不是真正的主机系统,而是容器本身。 So when you are running kibana and pointing the ELASTICSEARCH_URL
variable to localhost:9200
the kibana process will look for elasticsearch inside the kibana container which of course isn't running there. 因此,当您运行kibana并将
ELASTICSEARCH_URL
变量指向localhost:9200
,kibana进程将在kibana容器内查找弹性搜索,该容器当然不在那里运行。
You already introduced some custom network that you referenced when starting the containers. 您已经介绍了启动容器时引用的一些自定义网络。 All containers running in the same network can reference each other via name on their
expose
d ports (see Dockerfiles). 在同一网络中运行的所有容器可以通过其
expose
d端口上的名称相互引用(请参阅Dockerfiles)。 As you named your elasticsearch container elasticsearch_2_4
, you can reference the http endpoint of elasticsearch as http://elasticsearch_2_4:9200
. 当您将elasticsearch容器命名为
elasticsearch_2_4
,可以将elasticsearch的http端点引用为http://elasticsearch_2_4:9200
。
docker run -d --network mynetwork -e ELASTICSEARCH_URL=http://elasticsearch_2_4:9200 -p 5601:5601 kibana:4.6
As long as you don't need to access the elasticsearch instance directly, you can even omit mapping the ports 9200 and 9300 to your host. 只要您不需要直接访问elasticsearch实例,您甚至可以省略将端口9200和9300映射到主机。
Instead of starting all containers on their own, I would also suggest to use docker-compose
to manage all services and parameters. 我还建议使用
docker-compose
来管理所有服务和参数,而不是自己启动所有容器。 You should also consider mounting a local folder as volume to have the data persisted. 您还应该考虑将本地文件夹作为卷安装以保持数据。 This could be your compose file.
这可能是你的撰写文件。 Add the
networks
, if you need to have the external network, otherwise this setup just creates a network for you. 添加
networks
,如果你需要有外部网络,否则此设置只为你创建一个网络。
version: "2"
services:
elasticsearch:
image: elasticsearch:2.4
ports:
- "9200:9200"
volumes:
- ./esdata/:/usr/share/elasticsearch/data/
kibana:
image: kibana:4.6
ports:
- "5601:5601"
environment:
- ELASTICSEARCH_URL=http://elasticsearch:9200
I changed network configuration for Kibana container and after this it works fine: 我更改了Kibana容器的网络配置,之后它工作正常:
Test: 测试:
docker run -d -e ELASTICSEARCH_URL=http://yourhostip:9200 -p 5601:5601 kibana:4.6
You can test with your host ip or the ip identified by docker0 in ifconfig 您可以使用主机ip或ifconfig中docker0标识的ip进行测试
Regards 问候
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.