下载镜像
[root@iZwz9igpak5b59g11ute20Z ~]# docker pull elasticsearch:6.5.3
6.5.3: Pulling from library/elasticsearch
a02a4930cb5d: Pull complete
be45049b8682: Pull complete
ecc41567a2a1: Pull complete
cace8b63b322: Pull complete
612255c52193: Pull complete
288443200e8a: Pull complete
d0a09dbf50fd: Pull complete
4fc86479577b: Pull complete
Digest: sha256:697620435a3a4266f7ed4ee23ddbe21eb6ed91bc27583134fe6b19af40af721d
Status: Downloaded newer image for elasticsearch:6.5.3
docker.io/library/elasticsearch:6.5.3
运行容器
[root@iZwz9igpak5b59g11ute20Z ~]# docker run -d -p 9200:9200 -p 9300:9300 --name elasticsearch-6.5.3 elasticsearch:6.5.3
1cb82e86699dfa1b031f62451ad986793610ecf57452ccd6f9aee293daf71a02
容易挂掉用这个启动(增加上内存限制启动)
[root@iZwz9igpak5b59g11ute20Z ~]# docker run -d --name elasticsearch-6.5.3-01 -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" elasticsearch:6.5.3
4ccce45c95a267487c160a46a997d46d45181dcde7c3c77d628ebec9f993f024
进入容器
[root@iZwz9igpak5b59g11ute20Z ~]# docker exec -it 4ccce45c95a267487c160a46a997d46d45181dcde7c3c77d628ebec9f993f024 /bin/bash
[root@4ccce45c95a2 elasticsearch]#
测试
[root@4ccce45c95a2 elasticsearch]# curl localhost:9200
{
"name" : "GPC8OcK",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "o0--RP1FTg-tS8CmsuTNxg",
"version" : {
"number" : "6.5.3",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "159a78a",
"build_date" : "2018-12-06T20:11:28.826501Z",
"build_snapshot" : false,
"lucene_version" : "7.5.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
安装 ik 分词器
[root@4ccce45c95a2 elasticsearch]# ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.5.3/elasticsearch-analysis-ik-6.5.3.zip
-> Downloading https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.5.3/elasticsearch-analysis-ik-6.5.3.zip
修改 es 配置文件
修改 es 配置文件:`vi ./config/elasticsearch.yml
cluster.name: "docker-cluster"
network.host: 0.0.0.0
# minimum_master_nodes need to be explicitly set when bound on a public IP
# set to 1 to allow single node clusters
# Details: https://github.com/elastic/elasticsearch/pull/17288
discovery.zen.minimum_master_nodes: 1
# just for elasticsearch-head plugin
http.cors.enabled: true
http.cors.allow-origin: "*"
安装elasticsearch-head插件
1、拉取镜像
[root@iZwz9igpak5b59g11ute20Z ~]# docker pull mobz/elasticsearch-head:5
5: Pulling from mobz/elasticsearch-head
2、启动容器
docker run -d --name es-head -p 9100:9100 mobz/elasticsearch-head:5
3、访问
链接访问: http://ip:9100
退出容器
exit
停止容器
docker stop elasticsearch-6.5.3
启动容器
docker start elasticsearch-6.5.3