简体   繁体   English

docker-elk - 它如何持久化弹性搜索索引?

[英]docker-elk - how is it persisting elasticsearch index?

I'm just getting to grips with Docker and docker-compose, trying to create a development environment for Elasticsearch which I will deploy later.我刚刚开始掌握 Docker 和 docker-compose,试图为 Elasticsearch 创建一个开发环境,我将在稍后部署它。

I've been using docker-elk as a reference, and I've managed to create a working Elasticsearch container, seed it, and use it in my project.我一直在使用docker-elk作为参考,我已经成功地创建了一个有效的 Elasticsearch 容器,为其播种,并在我的项目中使用它。

As I understand it, Docker containers don't persist data, unless you use the Volumes API and create a volume outside the container that the container then accesses (read that here ).据我了解,Docker 容器不会持久保存数据,除非您使用 Volumes API 并在容器外部创建一个容器然后访问的卷(在此处阅读)。

However docker-elk only uses Volumes to share a config yml file, but somehow my elastic indices are persisting when I bring the container down and up again.然而 docker-elk 只使用 Volumes 来共享一个配置 yml 文件,但不知何故,当我再次关闭和打开容器时,我的弹性指数仍然存在。

From the docker-elk readme:来自 docker-elk 自述文件:

The data stored in Elasticsearch will be persisted after container reboot but not after container removal.存储在 Elasticsearch 中的数据将在容器重启后持久化,但在容器移除后不会持久化。

Can someone please explain what part of the below configuration is allowing the docker container to persist the index?有人可以解释以下配置的哪一部分允许docker容器保留索引吗?

docker-compose.yml docker-compose.yml

version: '2'

services:
  elasticsearch:
    build:
      context: build/elasticsearch/
    volumes:
      - ./build/elasticsearch/config.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
    ports:
      - "9200:9200"
      - "9300:9300"
    environment:
      ES_JAVA_OPTS: "-Xmx256m -Xms256m"
    networks:
      - elk

networks:
  elk:
    driver: bridge

build/elasticsearch/Dockerfile构建/弹性搜索/Dockerfile

FROM docker.elastic.co/elasticsearch/elasticsearch-oss:6.0.0

build/elasticsearch/config.yml构建/elasticsearch/config.yml

cluster.name: "docker-cluster"
network.host: 0.0.0.0
discovery.zen.minimum_master_nodes: 1
discovery.type: single-node

As you may know, a container is a sandbox.您可能知道,容器就是沙箱。 It has a filesystem with a structure very identical to a typical linux OS.它有一个文件系统,其结构与典型的 linux 操作系统非常相似。 The container only sees those files and folders that are in this filesystem.容器只能看到在这个文件系统中的那些文件和文件夹。

The process running inside the container writes it data and config to files in this filesystem.在容器内运行的进程将其数据和配置写入此文件系统中的文件。 This process is unaware that it is running in a container or on a VM.此进程不知道它是在容器中还是在 VM 上运行。 Thus the data is persisted in files and folder in this filesystem.因此,数据保存在此文件系统中的文件和文件夹中。

Now when you remove a container using docker rm ... those files are deleted with the container and thus you lose the data unless you use volumes which backup this data on the host.现在,当您使用docker rm ...删除容器时docker rm ...这些文件将随容器一起删除,因此您会丢失数据,除非您使用在主机上备份此数据的卷。

On the other hand, stopping and starting the container does not remove the container files and thus the data is still there when you restart the container.另一方面,停止和启动容器不会删除容器文件,因此当您重新启动容器时数据仍然存在。

To supplement the accepted answer, for anyone who is looking for how to persist the data.为了补充接受的答案,对于正在寻找如何保留数据的任何人。 Add a volume as mentioned in the question.添加问题中提到的volume

version: '3'

services:
  
  elasticsearch: # Elasticsearch Instance
    container_name: es-search
    image: docker.elastic.co/elasticsearch/elasticsearch:6.1.1
    volumes: # Persist ES data in seperate "esdata" volume
      - esdata:/usr/share/elasticsearch/data
    environment:
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - discovery.type=single-node
    ports: # Expose Elasticsearch ports
      - "9300:9300"
      - "9200:9200"

volumes: # Define seperate volume for Elasticsearch data
  esdata: ./my/esdata # path of your persisted data here

I found a guide for elastic docker here: https://blog.patricktriest.com/text-search-docker-elasticsearch/我在这里找到了弹性泊坞窗的指南: https : //blog.patricktriest.com/text-search-docker-elasticsearch/

可以使用以下命令观察UUID 中的索引及其映射。

curl 'localhost:9200/_cat/indices?v'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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