创建容器卷

docker volume create elasticsearch-config -o 'device=/home/docker/elastic/config' -o 'type=none' -o 'o=bind'

启动容器

docker run -d --name elasticsearch --net somenetwork -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -v /home/docker/elastic/data:/usr/share/elasticsearch/data -v elasticsearch-config:/usr/share/elasticsearch/config -v  /home/docker/elastic/plugins:/usr/share/elasticsearch/plugins elasticsearch:7.16.1

ES默认开启Https,容器版本的需要自己重置ES的密码

修改ES密码

[root@localhost config]# docker exec -it elasticsearch bash
elasticsearch@79f1d0300fe6:~$ cd bin/
elasticsearch@79f1d0300fe6:~/bin$ elasticsearch-reset-password -u elastic elastic
WARNING: Group of file [/usr/share/elasticsearch/config/users] used to be [elasticsearch], but now is [root]
WARNING: Group of file [/usr/share/elasticsearch/config/users_roles] used to be [elasticsearch], but now is [root]
This tool will reset the password of the [elastic] user to an autogenerated value.
The password will be printed in the console.
Please confirm that you would like to continue [y/N]y


Password for the [elastic] user successfully reset.
New value: UY1F9U=J4s7hnI3_9PM+

ES增加跨域

使用 ​​vim​​​ 修改 ​​/home/docker/elastic/config/elasticsearch.yml​​ 文件,增加以下内容:

#---------------------- BEGIN CORS ---------------------------------------------
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: X-Requested-With,Content-Type,Content-Length,Authorization
#--------------------------------------------------------------------------------

ES8 把证书导入浏览器信任

证书位置在上面挂载的容器卷里面,路径位置在 ​​/home/docker/elastic/config/certs/http_ca.crt​​​ 中,对应ES的 ​​/usr/share/elasticsearch/config/certs/http_ca.crt​​ 。

chrome 设置-> 安全和隐私设置 -> 安全 -> 管理证书

Docker安装ElasticSearch_elasticsearch

找到 ​​Elasticsearch security auto-configuration HTTP CA​​ 证书, 点击信任设置始终信任。

Docker安装ElasticSearch_elastic_02