当前位置:   article > 正文

docker自定义镜像并使用

docker自定义镜像并使用

写在前面

本文看下如何自定义镜像。

ik包从这里 下载。

1:自定义带有ik的es镜像

先看下目录结构

/opt/program/mychinese
[root@localhost mychinese]# ll
total 16
-rw-r--r-- 1 root root 1153 Feb  5 04:18 docker-compose.yaml
-rw-rw-r-- 1 elk  elk   291 Feb  5 04:17 Dockerfile
drwxr-xr-x 3 root root  243 Feb  5 03:27 ik710
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

ik710目录就是ik的解压内容,后续回安装到es,直接拷贝到es的plugins目录就行。

Dockerfile内容:

FROM docker.elastic.co/elasticsearch/elasticsearch:7.1.0
RUN mkdir /usr/share/elasticsearch/plugins/ik710
#RUN cd /usr/share/elasticsearch/plugins/ik710
ADD ik710 /usr/share/elasticsearch/plugins/ik710
# CMD echo "es will start!!!"
# CMD ["/usr/share/elasticsearch/bin/elasticsearch", "-d"]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

接着就可以构建镜像了:

docker build -t mychinese:1.2 .

[root@localhost mychinese]# docker images
REPOSITORY                                      TAG                 IMAGE ID            CREATED             SIZE
mychinese                                       1.2                 d0aec608ff4f        12 minutes ago      904 MB
...
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

接着就可以使用docker-compose 启动了,内容如下:

version: '2.2'
services:
  elasticsearch:
    image: mychinese:1.2
    container_name: es7_011
    environment:
      - cluster.name=geektime
      - node.name=es7_011
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - discovery.seed_hosts=es7_011,es7_012
      - cluster.initial_master_nodes=es7_011,es7_012
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - es7data1:/usr/share/elasticsearch/data
    ports:
      - 9220:9200
    networks:
      - es7net
  elasticsearch2:
    image: mychinese:1.2
    container_name: es7_012
    environment:
      - cluster.name=geektime
      - node.name=es7_012
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - discovery.seed_hosts=es7_011,es7_012
      - cluster.initial_master_nodes=es7_011,es7_012
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - es7data2:/usr/share/elasticsearch/data
    networks:
      - es7net


volumes:
  es7data1:
    driver: local
  es7data2:
    driver: local

networks:
  es7net:
    driver: bridge
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51

启动:

[root@localhost mychinese]# docker-compose up 
Creating es7_011 ... done
Creating es7_012 ... done
Attaching to es7_012, es7_011
es7_011           | {"type": "server", "timestamp": "2024-02-05T09:32:29,486+0000", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "geektime", "node.name": "es7_011",  "message": "loaded plugin [analysis-ik]"  } # 这里可以看到加载analysis-ik插件了
...
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

查看:
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/81827
推荐阅读
相关标签
  

闽ICP备14008679号