如何使用 docker compose 安装 ElasticSearch 插件
How to install ElasticSeach plugins using docker compose
我有一个带有弹性搜索图像的 docker-compose.yml 文件:
elasticsearch:
image: elasticsearch
ports:
- "9200:9200"
container_name: custom_elasticsearch_1
如果我想安装额外的插件,如 HQ 接口或附件映射器,我必须使用以下命令进行手动安装:
$ docker exec custom_elasticsearch_1 plugin install royrusso/elasticsearch-HQ
$ docker exec custom_elasticsearch_1 plugin install mapper-attachments
有没有办法在我 运行 docker-compose up
命令时自动安装它们?
Here is a blog post by Elastic pertaining to exactly that! You need to use a Dockerfile 执行扩展图像的命令。您的 Dockerfile 将如下所示:
FROM custom_elasticsearch_1
RUN elasticsearch-plugin install royrusso/elasticsearch-HQ
这对我有用。之前安装插件,然后继续启动elasticsearch。
elasticsearch:
image: elasticsearch
command:
- sh
- -c
- "plugin list | grep -q plugin_name || plugin install plugin_name;
/docker-entrypoint.sh elasticsearch"
如果您使用的是来自 sebp/elk
的 ELK
堆栈
您需要像
一样设置您的 Dockerfile
FROM sebp/elk
ENV ES_HOME /opt/elasticsearch
WORKDIR ${ES_HOME}
RUN yes | CONF_DIR=/etc/elasticsearch gosu elasticsearch bin/elasticsearch-plugin \
install -b mapper-attachments
在 https://elk-docker.readthedocs.io/#installing-elasticsearch-plugins.
上看到的
它也应该只适用于 Elastic Search。
受@NickPridorozhko 的回答启发,但使用 elasticsearch^7.0.0(使用 docker stack / swarm)进行了更新和测试,使用 analysis-icu 的示例:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.3.0
user: elasticsearch
command: >
/bin/sh -c "./bin/elasticsearch-plugin list | grep -q analysis-icu
|| ./bin/elasticsearch-plugin install analysis-icu;
/usr/local/bin/docker-entrypoint.sh"
...
主要区别在于 ^7.0.0 的更新命令,以及使用 docker 入口点而不是 ./bin/elasticsearch(在堆栈的上下文中,您会收到与到可生成进程的限制)。
ingest-attachment 插件需要额外的权限并在安装过程中提示用户。我使用了 yes
命令:
elasticsearch:
image: elasticsearch:6.8.12
command: >
/bin/sh -c "./bin/elasticsearch-plugin list | grep -q ingest-attachment
|| yes | ./bin/elasticsearch-plugin install --silent ingest-attachment;
/usr/local/bin/docker-entrypoint.sh eswrapper"
Elasticsearch v6.8.15 示例。
为简单起见,我们将使用 docker-compose.yml
和 Dockerfile
.
Dockerfile
的内容:
FROM docker.elastic.co/elasticsearch/elasticsearch:6.8.15
RUN elasticsearch-plugin install analysis-icu
RUN elasticsearch-plugin install analysis-phonetic
内容docker-compose.yml
:
version: '2.2'
services:
elasticsearch:
#image: docker.elastic.co/elasticsearch/elasticsearch:6.8.15
build:
context: ./
dockerfile: Dockerfile
container_name: elasticsearch
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- http.cors.enabled=true
- http.cors.allow-origin=*
- http.cors.allow-headers=X-Requested-With,Content-Type,Content-Length,Authorization
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata1:/usr/share/elasticsearch/data
- esplugins1:/usr/share/elasticsearch/plugins
ports:
- 9268:9200
networks:
- esnet
elasticsearch2:
#image: docker.elastic.co/elasticsearch/elasticsearch:6.8.15\
build:
context: ./
dockerfile: Dockerfile
container_name: elasticsearch2
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- http.cors.enabled=true
- http.cors.allow-origin=*
- http.cors.allow-headers=X-Requested-With,Content-Type,Content-Length,Authorization
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- "discovery.zen.ping.unicast.hosts=elasticsearch"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata2:/usr/share/elasticsearch/data
- esplugins2:/usr/share/elasticsearch/plugins
networks:
- esnet
volumes:
esdata1:
driver: local
esdata2:
driver: local
esplugins1:
driver: local
esplugins2:
driver: local
networks:
esnet:
这是来自 Elasticsearch 网站本身 https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docker.html#docker-cli-run-prod-mode 的默认 Elasticsearch 6.8.15 docker-compose.yml
文件。我为其中两个节点添加了两个 named data volumes
、esplugins1
和 esplugins2
。所以这些插件可以在 docker-compose down
.
之间持久化
请注意,如果您 运行 docker-compose down -v
那么这些卷将被删除!
我注释掉了 image
行并将该图像移动到 Dockerfile
。然后使用 RUN
命令添加 elasticsearch-plugin
安装命令。这个 elasticsearch-plugin
命令在 elasticsearch 容器中是原生可用的。一旦你进入容器 shell.
,你就可以检查这个
我有一个带有弹性搜索图像的 docker-compose.yml 文件:
elasticsearch:
image: elasticsearch
ports:
- "9200:9200"
container_name: custom_elasticsearch_1
如果我想安装额外的插件,如 HQ 接口或附件映射器,我必须使用以下命令进行手动安装:
$ docker exec custom_elasticsearch_1 plugin install royrusso/elasticsearch-HQ
$ docker exec custom_elasticsearch_1 plugin install mapper-attachments
有没有办法在我 运行 docker-compose up
命令时自动安装它们?
Here is a blog post by Elastic pertaining to exactly that! You need to use a Dockerfile 执行扩展图像的命令。您的 Dockerfile 将如下所示:
FROM custom_elasticsearch_1
RUN elasticsearch-plugin install royrusso/elasticsearch-HQ
这对我有用。之前安装插件,然后继续启动elasticsearch。
elasticsearch:
image: elasticsearch
command:
- sh
- -c
- "plugin list | grep -q plugin_name || plugin install plugin_name;
/docker-entrypoint.sh elasticsearch"
如果您使用的是来自 sebp/elk
ELK
堆栈
您需要像
一样设置您的Dockerfile
FROM sebp/elk
ENV ES_HOME /opt/elasticsearch
WORKDIR ${ES_HOME}
RUN yes | CONF_DIR=/etc/elasticsearch gosu elasticsearch bin/elasticsearch-plugin \
install -b mapper-attachments
在 https://elk-docker.readthedocs.io/#installing-elasticsearch-plugins.
上看到的它也应该只适用于 Elastic Search。
受@NickPridorozhko 的回答启发,但使用 elasticsearch^7.0.0(使用 docker stack / swarm)进行了更新和测试,使用 analysis-icu 的示例:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.3.0
user: elasticsearch
command: >
/bin/sh -c "./bin/elasticsearch-plugin list | grep -q analysis-icu
|| ./bin/elasticsearch-plugin install analysis-icu;
/usr/local/bin/docker-entrypoint.sh"
...
主要区别在于 ^7.0.0 的更新命令,以及使用 docker 入口点而不是 ./bin/elasticsearch(在堆栈的上下文中,您会收到与到可生成进程的限制)。
ingest-attachment 插件需要额外的权限并在安装过程中提示用户。我使用了 yes
命令:
elasticsearch:
image: elasticsearch:6.8.12
command: >
/bin/sh -c "./bin/elasticsearch-plugin list | grep -q ingest-attachment
|| yes | ./bin/elasticsearch-plugin install --silent ingest-attachment;
/usr/local/bin/docker-entrypoint.sh eswrapper"
Elasticsearch v6.8.15 示例。
为简单起见,我们将使用 docker-compose.yml
和 Dockerfile
.
Dockerfile
的内容:
FROM docker.elastic.co/elasticsearch/elasticsearch:6.8.15
RUN elasticsearch-plugin install analysis-icu
RUN elasticsearch-plugin install analysis-phonetic
内容docker-compose.yml
:
version: '2.2'
services:
elasticsearch:
#image: docker.elastic.co/elasticsearch/elasticsearch:6.8.15
build:
context: ./
dockerfile: Dockerfile
container_name: elasticsearch
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- http.cors.enabled=true
- http.cors.allow-origin=*
- http.cors.allow-headers=X-Requested-With,Content-Type,Content-Length,Authorization
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata1:/usr/share/elasticsearch/data
- esplugins1:/usr/share/elasticsearch/plugins
ports:
- 9268:9200
networks:
- esnet
elasticsearch2:
#image: docker.elastic.co/elasticsearch/elasticsearch:6.8.15\
build:
context: ./
dockerfile: Dockerfile
container_name: elasticsearch2
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- http.cors.enabled=true
- http.cors.allow-origin=*
- http.cors.allow-headers=X-Requested-With,Content-Type,Content-Length,Authorization
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- "discovery.zen.ping.unicast.hosts=elasticsearch"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata2:/usr/share/elasticsearch/data
- esplugins2:/usr/share/elasticsearch/plugins
networks:
- esnet
volumes:
esdata1:
driver: local
esdata2:
driver: local
esplugins1:
driver: local
esplugins2:
driver: local
networks:
esnet:
这是来自 Elasticsearch 网站本身 https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docker.html#docker-cli-run-prod-mode 的默认 Elasticsearch 6.8.15 docker-compose.yml
文件。我为其中两个节点添加了两个 named data volumes
、esplugins1
和 esplugins2
。所以这些插件可以在 docker-compose down
.
请注意,如果您 运行 docker-compose down -v
那么这些卷将被删除!
我注释掉了 image
行并将该图像移动到 Dockerfile
。然后使用 RUN
命令添加 elasticsearch-plugin
安装命令。这个 elasticsearch-plugin
命令在 elasticsearch 容器中是原生可用的。一旦你进入容器 shell.