Ubuntu 24.04 通过 docker 安装 elasticsearch

更新日期: 2025-07-27 阅读次数: 30 字数: 230 分类: docker

折腾半天,感觉还是通过 docker 安装 elasticsearch 最简单。 毕竟只是开发环境搭建,不想浪费时间在安装和配置上。用 docker 最节省时间。

这也是我第一次通过 WSL2 使用 docker。主要是为了规避 Windows 上的 docker destop 的商业授权问题。

docker-compose.yml

services:
  elasticsearch:
    image: m.daocloud.io/docker.io/elasticsearch:7.17.22
    ports:
      - "9200:9200"
    environment:
      - "discovery.type=single-node"
      - xpack.security.enabled=false
      ## Avoid test failures due to small disks
      ## More info at https://github.com/markshust/docker-magento/issues/488
      #- "cluster.routing.allocation.disk.threshold_enabled=false"
      #- "index.blocks.read_only_allow_delete"
      # Uncomment to set custom heap size to avoid memory errors
      - "ES_JAVA_OPTS=-Xms1g -Xmx1g"
      ## Uncomment to increase the virtual memory map count
      #- "max_map_count=262144"
    volumes:
      - ./services/es_data:/usr/share/elasticsearch/data
      - ./services/es_log:/var/log/elasticsearch

如果是在海外服务器上使用,并不需要国内的镜像前缀 m.daocloud.io/docker.io/

启动

sudo docker compose up -d

查看状态

$ sudo docker compose ps
NAME                          IMAGE                                           COMMAND                  SERVICE         CREATED         STATUS         PORTS
magento_dev-elasticsearch-1   m.daocloud.io/docker.io/elasticsearch:7.17.22   "/bin/tini -- /usr/l…"   elasticsearch   3 seconds ago   Up 2 seconds   0.0.0.0:9200->9200/tcp, [::]:9200->9200/tcp, 9300/tcp

微信关注我哦 👍

大象工具微信公众号

我是来自山东烟台的一名开发者,有感兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式