关于docker:docker使用系列之4docker安装ESelasticsearch

46次阅读

共计 1658 个字符,预计需要花费 5 分钟才能阅读完成。

关上容器镜像官网

2.5.1 镜像官网搜寻 elasticsearch

2.5.2 间接拉取镜像:

sudo docker pull elasticsearch:7.4.2

2.5.3 装置 es 容器

2.5.3.1 创立所需目录:

mkdir -p /mydata/elasticsearch/config/
mkdir -p /mydata/elasticsearch/data/
echo "http.host: 0.0.0.0">>/mydata/elasticsearch/config/elasticsearch.yml

2.5.3.2 创立实例并启动:

elasticsearch:

sudo docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \
-e "discovery.type=single-node" \
-e ES_JAVA_OPS="-Xms128m -Xmx512m" \
-v /mydata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /mydata/elasticsearch/data:/usr/share/elasticsearch/data \
-v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-d elasticsearch:7.4.2

参数阐明:

-p 9200:9200 将容器的 9200 端口映射到主机的 9200 端口;
–name elasticsearch 给以后启动的容器取名叫 elasticsearch
-v /mydata/elasticsearch/data:/usr/share/elasticsearch/data 将数据文件夹挂载到主机;
-v /mydata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml 将配置文件挂载到主机;
-d 当前台形式运行 (daemon)
-e ES_JAVA_OPS=”-Xms64m -Xmx128m” 测试时限定内存小一点

2.5.3.3 启动 elasticsearch 容器

docker start elasticsearch

2.5.4 拜访 elasticsearch

http://192.168.56.100:9200/

2.5.5 问题小结

如果遇到已有容器的抵触, 须要删掉原来的:

docker: Error response from daemon: Conflict. The container name "/elasticsearch" is already in use by container "1a2e7069114ede501f687e3435b76fbc546061959b773f51681d10008bab4342". You have to remove (or rename) that container to be able to reuse that name.

解决形式: docker ps -a 列出所有, 删掉之前的镜像:

[root@localhost conf]# docker ps -a
CONTAINER ID    IMAGE                    CREATED            STATUS                                PORTS                                              NAMES
1a2e7069114e    elasticsearch:7.4.2        9 minutes ago    Exited (143) About a minute ago        0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp    elasticsearch

[root@localhost conf]# docker rm 1a2e7069114e
1a2e7069114e
[root@localhost conf]# docker ps -a
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                            NAMES

正文完
 0