简体   繁体   中英

How to access an Elasticsearch stored in a Docker container from outside?

I'm currently runnning Elasticsearch (ES) 5.5 inside a Docker container. (See below)

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"
}

I've changed the elasticsearch.yml file to look like this:

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

I can currently get my indexes through curl -XGET commands. The thing here is that I wanted to be able to do http requests to this ES instance using it's Ip Address instead of the 'localhost:9200' setting starting from my machine (Mac OS X).

So, what I've tried already:

1) I've tried doing it in Postman getting the following response:

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) I also tried in Sense (Plugin for Chrome):

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

3) Running a curl from my machine's terminal won't do it too.

What am I missing here?

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

docker.for.mac.localhost

You should use the value specified under container name in the YML file to connect to your cluster. Example:

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

In this case, elastic search is located at http://example_elasticsearch:9200 . Note that example_elasticsearch is the name of the container and may be used the same way as machine name or host name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM