1、拉取镜像
docker pull elasticsearch:8.8.1
2、在机器本地新建文件夹并赋予权限
mkdir -p /home/elasticsearch/config
mkdir -p /home/elasticsearch/data
mkdir -p /home/elasticsearch/plugins
chmod 777 /home/elasticsearch/config
chmod 777 /home/elasticsearch/data
chmod 777 /home/elasticsearch/plugins
3、运行一个临时容器
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:8.8.1
4、将容器里的config文件夹的东西拷贝到宿主机上
docker cp elasticsearch:/usr/share/elasticsearch/config /home/elasticsearch
5、删除临时容器
docker stop elasticsearch
docker rm -f elasticsearch
6、修改elasticsearch.yml文件
7、启动容器
docker run \
--restart=always \
--name es \
--privileged=true \
-p 9200:9200 \
-p 9300:9300 \
-v /home/elasticsearch/config:/usr/share/elasticsearch/config \
-v /home/elasticsearch/data:/usr/share/elasticsearch/data \
-v /home/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-e ES_JAVA_OPTS="-Xms512m -Xmx512m" \
-e "discovery.type=single-node" \
-d elasticsearch:8.8.1
8、es访问界面
http://你的ip:9200