Elasticsearch docker刻录图像中的数据

时间:2017-06-26 06:19:40

标签: elasticsearch docker docker-compose

我尝试使用预加载的数据构建弹性搜索图像。我正在从S3进行恢复操作。

FROM elasticsearch:5.3.1

ARG bucket
ARG access_key
ARG secret_key
ARG repository
ARG snapshot

ENV ES_JAVA_OPTS="-Des.path.conf=/etc/elasticsearch"

RUN elasticsearch-plugin install repository-s3

ADD https://raw.githubusercontent.com/vishnubob/wait-for-it/e1f115e4ca285c3c24e847c4dd4be955e0ed51c2/wait-for-it.sh wait-for-it.sh 

RUN chmod +x wait-for-it.sh

RUN /docker-entrypoint.sh elasticsearch -p /tmp/epid & ./wait-for-it.sh -t 0 localhost:9200 -- echo "Elasticsearch is ready!" && \
curl -H 'Content-Type: application/json' -X PUT "localhost:9200/_snapshot/$repository" -d '{ "type": "s3", "settings": { "bucket": "'$bucket'", "access_key": "'$access_key'", "secret_key": "'$secret_key'" } }' && \
curl -H "Content-Type: application/json" -X POST "localhost:9200/_snapshot/$repository/$snapshot/_restore?wait_for_completion=true" -d '{ "indices": "myindex", "ignore_unavailable": true, "index_settings": { "index.number_of_replicas": 0 }, "ignore_index_settings": [ "index.refresh_interval" ] }' && \
curl -H "Content-Type: application/json" -X GET "localhost:9200/_cat/indices"

RUN kill $(cat /tmp/epid) && wait $(cat /tmp/epid); exit 0;

CMD ["-E", "network.host=0.0.0.0", "-E", "discovery.zen.minimum_master_nodes=1"]

图像构建成功,但是当我启动容器时索引会丢失。我没有使用任何卷。我错过了什么?

version: '2'

services:
  elasticsearch:
    container_name: "elasticsearch"
    build: 
      context: ./elasticsearch/
      args:
        access_key: access_key_here
        secret_key: secret_key_here
        bucket: bucket_here
        repository: repository_here
        snapshot: snapshot_here
    ports:
      - "9200:9200"
      - "9300:9300"
    environment:
      ES_JAVA_OPTS: "-Xms1g -Xmx1g -Des.path.conf=/etc/elasticsearch"

1 个答案:

答案 0 :(得分:0)

似乎卷不能在图像中燃烧。保存所生成数据的目录由父图像指定为卷。唯一的方法是分叉父Dockerfile并删除卷部分。