准备
安装好Docker环境
下载镜像
Apr 13, 2022 拉取最新的镜像是8.1.2
root@redis01:/home/bigdata# docker pull elasticsearch # 查看镜像 root@redis01:/home/bigdata# docker images
启动镜像
root@redis01:/home/bigdata# docker run --name elasticsearch -d -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -e "discovery.type=single-node" -p 9200:9200 -p 9300:9300 elasticsearch:8.1.2 632afeaadbd0e236d5cf584b23c6f076d6114be4f3f72a618d1ec332036f8165
访问
检查端口有没有映射到宿主机上
ss -ntulp | grep 9200
解决
方法一:进入容器,修改配置文件
# 查看容器 root@redis01:/var/lib/docker# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 632afeaadbd0 elasticsearch:8.1.2 "/bin/tini -- /usr/l…" 19 minutes ago Up 19 minutes 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch # 进入容器 root@redis01:/var/lib/docker# docker exec -it 632afeaadbd0 /bin/bash # 编辑配置文件 elasticsearch@632afeaadbd0:~$ vim config/elasticsearch.yml bash: vim: command not found elasticsearch@632afeaadbd0:~$ vi config/elasticsearch.yml
修改配置文件
config/elasticsearch.yml
,vi如果不好编辑,容器中安装vim。可以参考:Docker Note4:镜像中安装vim 重启镜像
root@redis01:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 632afeaadbd0 elasticsearch:8.1.2 "/bin/tini -- /usr/l…" 42 minutes ago Up 42 minutes 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch root@redis01:~# docker restart 632afeaadbd0 632afeaadbd0
方法二:数据卷挂载
# 1. 进入容器,获取到配置文件目录 root@redis01:~/es-kibana# docker exec -it ca5bfef43138 bash elasticsearch@ca5bfef43138:~$ cd config/ elasticsearch@ca5bfef43138:~/config$ pwd /usr/share/elasticsearch/config # 2. 创建配置文件 root@redis01:/usr/local/docker/es/config# vim elasticsearch.yml
elasticsearch.yml
配置文件信息network.host: 0.0.0.0 http.port: 9200 # Enable security features xpack.security.enabled: false xpack.security.enrollment.enabled: true
以数据挂载方式启动
# 删除容器 root@redis01:/usr/local/docker/es/config# docker rm -f ca5bfef43138 # 数据挂 root@redis01:/home/bigdata# docker run -d \ --name=elasticsearch \ -v /usr/local/docker/es/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \ -e ES_JAVA_OPTS="-Xms512m -Xmx512m" \ -e "discovery.type=single-node" \ -p 9200:9200 \ -p 9300:9300 \ elasticsearch:8.1.2