启动es这种容器需要考虑几个问题

  1. 端口暴露问题:9200、9300
  2. 数据卷的挂载问题:data、plugins、conf
  3. 吃内存 "ES_JAVA_OPTS=-Xms512m -Xmx512m"

1、下载elasticsearch

[root@localhost ~]# docker pull elasticsearch
Using default tag: latest
latest: Pulling from library/elasticsearch
05d1a5232b46: Pull complete 
5cee356eda6b: Pull complete 
89d3385f0fd3: Pull complete 
65dd87f6620b: Pull complete 
78a183a01190: Pull complete 
1a4499c85f97: Pull complete 
2c9d39b4bfc1: Pull complete 
1b1cec2222c9: Pull complete 
59ff4ce9df68: Pull complete 
1976bc3ee432: Pull complete 
5af49e8af381: Pull complete 
42c8b75ff7af: Pull complete 
7e6902915254: Pull complete 
99853874fa54: Pull complete 
596fbad6fcff: Pull complete 
Digest: sha256:a8081d995ef3443dc6d077093172a5931e02cdb8ffddbf05c67e01d348a9770e
Status: Downloaded newer image for elasticsearch:latest
docker.io/library/elasticsearch:latest
[root@localhost ~]# 

2、启动es测试

[root@localhost ~]# docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:latest
d29f5dc7717d2dfe08de4909fb7409226ef735fe4401c030b8fff376039b14c8
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE                  COMMAND                  CREATED          STATUS          PORTS                                                                                  NAMES
d29f5dc7717d   elasticsearch:latest   "/docker-entrypoint.…"   12 seconds ago   Up 10 seconds   0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp   elasticsearch

扩展命令
docker stats 容器id查看下cpu状态,可以发现占用资源很大

[root@localhost ~]# docker stats d29f5dc7717d

CONTAINER ID   NAME            CPU %     MEM USAGE / LIMIT   MEM %     NET I/O     BLOCK I/O         PIDS
d29f5dc7717d   elasticsearch   0.00%     2.197GiB / 3.7GiB   59.37%    656B / 0B   74.9MB / 28.7kB   38

CONTAINER ID   NAME            CPU %     MEM USAGE / LIMIT   MEM %     NET I/O     BLOCK I/O         PIDS
d29f5dc7717d   elasticsearch   0.00%     2.197GiB / 3.7GiB   59.37%    656B / 0B   74.9MB / 28.7kB   38

CONTAINER ID   NAME            CPU %     MEM USAGE / LIMIT   MEM %     NET I/O     BLOCK I/O         PIDS
d29f5dc7717d   elasticsearch   0.20%     2.197GiB / 3.7GiB   59.37%    656B / 0B   74.9MB / 28.7kB   38

3、测试访问

[root@localhost ~]# curl localhost:9200
{
  "name" : "FdGR8rc",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "SgdjG8kLS0uM37cNRms3FA",
  "version" : {
    "number" : "5.6.12",
    "build_hash" : "cfe3d9f",
    "build_date" : "2018-09-10T20:12:43.732Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.1"
  },
  "tagline" : "You Know, for Search"
}
[root@localhost ~]# 

2023-06-25_092726.jpg

4、增加内存限制启动

[root@localhost ~]# docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" elasticsearch:latest
e3980d0e7793e9451b3a00a079f0c8d1013ac3d3a2f1d3f5af161ec54d4378ca
[root@localhost ~]# 

启动后,使用docker stats 查看下CPU状态

[root@localhost ~]# docker stats e3980d0e7793

CONTAINER ID   NAME            CPU %     MEM USAGE / LIMIT   MEM %     NET I/O     BLOCK I/O       PIDS
e3980d0e7793   elasticsearch   0.00%     232MiB / 3.7GiB     6.12%     656B / 0B   22.5MB / 41kB   44

CONTAINER ID   NAME            CPU %     MEM USAGE / LIMIT   MEM %     NET I/O     BLOCK I/O       PIDS
e3980d0e7793   elasticsearch   0.00%     232MiB / 3.7GiB     6.12%     656B / 0B   22.5MB / 41kB   44

CONTAINER ID   NAME            CPU %     MEM USAGE / LIMIT   MEM %     NET I/O     BLOCK I/O       PIDS
e3980d0e7793   elasticsearch   0.31%     232MiB / 3.7GiB     6.12%     656B / 0B   22.5MB / 41kB   44

限制内存,验证测试结果

[root@localhost ~]# curl localhost:9200
{
  "name" : "Uk_U1aH",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "DmlhEcy9RbShVQsxwI0Hsg",
  "version" : {
    "number" : "5.6.12",
    "build_hash" : "cfe3d9f",
    "build_date" : "2018-09-10T20:12:43.732Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.1"
  },
  "tagline" : "You Know, for Search"
}
[root@localhost ~]# 

最后修改:2023 年 06 月 25 日
如果觉得我的文章对你有用,请随意赞赏