一、安装Docker Desktop

Docker Desktop: The #1 Containerization Tool for Developers | Docker

二、下载镜像

docker pull elasticsearch:8.11.1  # 这里以 8.11.1 版本为例

三、启动镜像

docker run -d --name es -p 9200:9200 \
  -e "ES_JAVA_OPTS=-Xms512m -Xmx512m" \
  -e "xpack.security.http.ssl.enabled=false" \
  -e "discovery.type=single-node" \
  elasticsearch:8.11.1

四、检查

# docker ps                                                                                                                                                                                    
CONTAINER ID   IMAGE                  COMMAND                  CREATED          STATUS          PORTS                                         NAMES
f2a1d6518feb   elasticsearch:8.11.1   "/bin/tini -- /usr/l…"   16 minutes ago   Up 16 minutes   0.0.0.0:9200->9200/tcp, [::]:9200->9200/tcp   es

五、浏览器访问

http://localhost:9200/

发现需要用户名和密码

# 进入容器执行
docker exec -it es \
/usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic -i

按提示输入新密码两次即可
This tool will reset the password of the [elastic] user.
You will be prompted to enter the password.
Please confirm that you would like to continue [y/N]y


Enter password for [elastic]:
Re-enter password for [elastic]:
Password for the [elastic] user successfully reset.

使用用户名和密码访问

curl -u elastic:123123 http://localhost:9200                                                                                                                                                 ─╯
{
  "name" : "f2a1d6518feb",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "JfaaonPMTlybVZCtxsL34g",
  "version" : {
    "number" : "8.11.1",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "6f9ff581fbcde658e6f69d6ce03050f060d1fd0c",
    "build_date" : "2023-11-11T10:05:59.421038163Z",
    "build_snapshot" : false,
    "lucene_version" : "9.8.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}

Logo

火山引擎开发者社区是火山引擎打造的AI技术生态平台,聚焦Agent与大模型开发,提供豆包系列模型(图像/视频/视觉)、智能分析与会话工具,并配套评测集、动手实验室及行业案例库。社区通过技术沙龙、挑战赛等活动促进开发者成长,新用户可领50万Tokens权益,助力构建智能应用。

更多推荐