1.临时在线安装
docker exec -it elasticsearch /bin/bash
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.17.0/elasticsearch-analysis-ik-7.17.0.zip
进入plugin查看已经装好ik
docker restart elasticsearch
2.Dockerfile长久保存成新的镜像
2.1 下载ik压缩包
下载https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.17.0/elasticsearch-analysis-ik-7.17.0.zip
mkdir /home/workspace/elasticsearch
cd /home/workspace/elasticsearch
rz上传到/home/workspace/elasticsearch
chmod 777 elasticsearch-analysis-ik-7.17.0.zip
2.2 创建Dockerfile文件
docker inspect elasticsearch 查看镜像元数据
cd /home/workspace/elasticsearch
vim Dockerfile:
FROM elasticsearch:7.17.0
WORKDIR /usr/share/elasticsearch
COPY elasticsearch-analysis-ik-7.17.0.zip /usr/share/elasticsearch
RUN sh -c ' /bin/echo -e "y\n" | ./bin/elasticsearch-plugin install file:///usr/share/elasticsearch/elasticsearch-analysis-ik-7.17.0.zip'
ENTRYPOINT ["/bin/tini","--","/usr/local/bin/docker-entrypoint.sh"]
2.3 重新构建镜像并运行
cd /home/workspace/elasticsearch
重新build docker镜像:docker build . -t elasticsearch_ik
启动elasticsearch_ik镜像:
#!/bin/bash
docker stop elasticsearch
docker rm -f elasticsearch
docker run -idt --name elasticsearch \
--restart=always \
-p 8901:9200 \
-p 9300:9300 \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms4g -Xmx4g" \
-v /data/elasticsearch/config:/usr/share/elasticsearch/config \
-v /data/elasticsearch/data:/usr/share/elasticsearch/data \
elasticsearch_ik
sleep 5s
docker logs elasticsearch