如何使用官方的docker elasticsearch容器? [英] How to use the official docker elasticsearch container?

查看:19
本文介绍了如何使用官方的docker elasticsearch容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 Dockerfile:

I have the following Dockerfile:

FROM docker.elastic.co/elasticsearch/elasticsearch:5.4.0
RUN elasticsearch
EXPOSE 80

我认为第 3 行永远不会到达.

I think the 3rd line is never reached.

当我尝试通过以下方式从本地计算机访问 dockercontainer 时:172.17.0.2:9300

When I try to access the dockercontainer from my local machine through: 172.17.0.2:9300

我什么都没得到,我错过了什么?我想从本地主机访问elasticsearch.

I get nothing, what am I missing? I want to access elasticsearch from the local host machine.

推荐答案

我建议使用 docker-compose(它使很多事情变得更容易)和以下配置.

I recommend using docker-compose (which makes lot of things much easier) with following configuration.

配置启动3个服务:elastic本身和额外的实用程序用于像 kibana 和 head 插件这样的开发(这些可以省略,如果你不需要它们).

Configuration starts 3 services: elastic itself and extra utilities for development like kibana and head plugin (these could be omitted, if you don't need them).

在同一个目录中,您将需要三个文件:

In the same directory you will need three files:

  • docker-compose.yml
  • elasticsearch.yml
  • kibana.yml

有以下内容:

docker-compose.yml

version: '2'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:5.4.0
    container_name: elasticsearch_540
    environment:
      - http.host=0.0.0.0
      - transport.host=0.0.0.0
      - "ES_JAVA_OPTS=-Xms1g -Xmx1g"
    volumes:
      - esdata:/usr/share/elasticsearch/data
      - ./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
    ports:
      - 9200:9200
      - 9300:9300
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    mem_limit: 2g
    cap_add:
      - IPC_LOCK
  kibana:
    image: docker.elastic.co/kibana/kibana:5.4.0
    container_name: kibana_540
    environment:
      - SERVER_HOST=0.0.0.0
    volumes:
      - ./kibana.yml:/usr/share/kibana/config/kibana.yml
    ports:
      - 5601:5601
  headPlugin:
    image: mobz/elasticsearch-head:5
    container_name: head_540
    ports:
      - 9100:9100

volumes:
  esdata:
    driver: local

elasticsearch.yml

cluster.name: "chimeo-docker-cluster"
node.name: "chimeo-docker-single-node"
network.host: 0.0.0.0

http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: "Authorization"

kibana.yml

server.name: kibana
server.host: "0"
elasticsearch.url: http://elasticsearch:9200
elasticsearch.username: elastic
elasticsearch.password: changeme
xpack.monitoring.ui.container.elasticsearch.enabled: true

运行

在同一目录中使用以上三个文件,并将该目录设置为当前工作目录(可能需要 sudo,取决于您如何设置 docker-compose):

Running

With above three files in the same directory and that directory set as current working directory you do (could require sudo, depends how you have your docker-compose set up):

docker-compose up

它将启动,您将看到来自三个不同服务的日志:elasticsearch_540kibana_540head_540.

It will start up and you will see logs from three different services: elasticsearch_540, kibana_540 and head_540.

初始启动后,您的弹性集群将可用于 9200 下的 http 和 9300 下的 tcp.如果集群启动,请使用以下 curl 进行验证:

After initial start up you will have your elastic cluster available for http under 9200 and for tcp under 9300. Validate with following curl if the cluster started up:

curl -u elastic:changeme http://localhost:9200/_cat/health 

然后您可以使用 kibana(具有弹性/changeme 凭据)查看和使用您的集群:

Then you can view and play with your cluster using either kibana (with credentials elastic / changeme):

http://localhost:5601/

或头部插件:

http://localhost:9100/?base_uri=http://localhost:9200&auth_user=elastic&auth_password=changeme

这篇关于如何使用官方的docker elasticsearch容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆