docker-composeでElasticsearchの検証環境を作る

公開日時
更新日時

dockerでElasticsearchの検証環境を作る。

# docker-compose.yml
version: '3'
services:
  datastore:
    image: busybox
    volumes:
      - es_data:/usr/share/elasticsearch/data

  elasticsearch:
    build: docker/elasticsearch
    ports:
      - "9200:9200"
    volumes:
      - es_data:/usr/share/elasticsearch/data
    environment:
      - discovery.type=single-node
      - http.cors.enabled=true
      - http.cors.allow-origin=/https?:\/\/localhost(:[0-9]+)?/

  elasticsearch-head:
    build: docker/head
    ports:
      - "9100:9100"
    depends_on:
      - elasticsearch
volumes:
  es_data:

headプラグインからアクセスできるようにhttp.cors.allow-originを設定している。

  • 日本語解析のプラグインをインストールしたDockerfileを用意
mkdir -p docker/elasticsearch
vi docker/elasticsearch/Dockerfile

FROM elasticsearch:7.3.1
RUN elasticsearch-plugin install analysis-kuromoji
RUN elasticsearch-plugin install analysis-icu
mkdir -p docker/head
vi docker/head/Dockerfile

FROM alpine:latest

RUN apk add --no-cache nodejs npm git

WORKDIR /app

RUN git clone git://github.com/mobz/elasticsearch-head.git .
RUN npm install
CMD npm run start
  • 起動と確認
docker-compose build
docker-compose up

これで http://localhost:9100 にアクセスするとGUIでElasticsearchの操作ができる。

参考


Related #elasticsearch

検証用のElasticsearchにUnassigned shardsが発生した

レプリカ数を0に変更して対応した

Logstashを使ってmysqlのデータをElasticsearchに同期する

tableにupdated_atとis_deletedを追加してLogstashのschedule機能を利用する