【问题标题】:How to access an Elasticsearch stored in a Docker container from outside?如何从外部访问存储在 Docker 容器中的 Elasticsearch?
【发布时间】:2018-01-18 15:57:55
【问题描述】:

我目前正在 Docker 容器中运行 Elasticsearch (ES) 5.5。 (见下文)

curl -XGET 'localhost:9200'
{
  "name" : "THbbezM",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "CtYdgNUzQrS5YRTRT7xNJw",
  "version" : {
    "number" : "5.5.0",
    "build_hash" : "260387d",
    "build_date" : "2017-06-30T23:16:05.735Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.0"
  },
  "tagline" : "You Know, for Search"
}

我已将 elasticsearch.yml 文件更改为如下所示:

http.host: 0.0.0.0

# Uncomment the following lines for a production cluster deployment
#transport.host: 0.0.0.0
#discovery.zen.minimum_master_nodes: 1

network.host: 0.0.0.0
http.port: 9200

我目前可以通过 curl -XGET 命令获取我的索引。这里的问题是,我希望能够使用它的 IP 地址而不是从我的机器(Mac OS X)开始的“localhost:9200”设置对这个 ES 实例进行 http 请求。

所以,我已经尝试过:

1) 我尝试在 Postman 中执行此操作,得到以下响应:

Could not get any response
There was an error connecting to X.X.X.X:9200/.
Why this might have happened:
The server couldn't send a response:
Ensure that the backend is working properly
Self-signed SSL certificates are being blocked:
Fix this by turning off 'SSL certificate verification' in Settings > General
Client certificates are required for this server:
Fix this by adding client certificates in Settings > Certificates
Request timeout:
Change request timeout in Settings > General

2)我也尝试过 Sense(Chrome 插件):

Request failed to get to the server (status code: 0):

3) 从我的机器终端运行 curl 也不会这样做。

我在这里缺少什么?

【问题讨论】:

  • 如果你在 Mac 上使用 docker,docker 会在后台创建一个 linux VM 并在这个 VM 中运行容器。您需要获取 VM 的 IP 并启用到容器的端口转发。
  • @yamenK 我正在使用 Docker 创建的 VM 的 IP。仍然无法正常工作。我已经使用 docker -inspect 检查了它
  • 这个答案可能会有所帮助:stackoverflow.com/questions/41752646/…
  • 使用 inspect 命令显示的 docker 容器 IP 与 VM IP 不同。容器有一个私有虚拟网络。
  • 你能帮我确定我在哪里可以获得虚拟机的 IP 地址吗?还没到那里...

标签: elasticsearch docker networking containers


【解决方案1】:

Docker for Mac 提供了一个您可以使用的 DNS 名称:

docker.for.mac.localhost

【讨论】:

  • 在指定绑定主机时是否应该在 elasticsearch.yml 中使用该 DNS 名称?
【解决方案2】:

您应该使用 YML 文件中容器名称下指定的值来连接到您的集群。示例:

services:
  elasticsearch:
    container_name: 'example_elasticsearch'
    image: 'docker.elastic.co/elasticsearch/elasticsearch:6.6.1'

在这种情况下,弹性搜索位于http://example_elasticsearch:9200。请注意,example_elasticsearch 是容器的名称,可以与机器名或主机名一样使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-03
    • 1970-01-01
    • 1970-01-01
    • 2016-12-29
    相关资源
    最近更新 更多