在centos7的基础镜像上构建elasticsearch镜像
时间: 2023-10-20 12:05:51 浏览: 172
1. 创建工作目录并进入
```
mkdir ~/elasticsearch
cd ~/elasticsearch
```
2. 创建Dockerfile文件
```
vi Dockerfile
```
3. 编辑Dockerfile文件
```
FROM centos:7
# 安装JDK
RUN yum -y install java-1.8.0-openjdk
# 下载elasticsearch
RUN curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.3-linux-x86_64.tar.gz
# 解压elasticsearch
RUN tar -xvf elasticsearch-7.9.3-linux-x86_64.tar.gz
# 删除压缩包
RUN rm elasticsearch-7.9.3-linux-x86_64.tar.gz
# 设置环境变量
ENV PATH /elasticsearch-7.9.3/bin:$PATH
# 暴露端口
EXPOSE 9200 9300
# 启动elasticsearch
CMD ["elasticsearch"]
```
4. 构建镜像
```
docker build -t elasticsearch:7.9.3 .
```
5. 运行容器
```
docker run -p 9200:9200 -p 9300:9300 -d elasticsearch:7.9.3
```
6. 访问elasticsearch
在浏览器中访问 `http://localhost:9200`,如果看到类似下面的输出,则elasticsearch已经成功运行。
```
{
"name" : "my-node",
"cluster_name" : "my-cluster",
"cluster_uuid" : "oW8a9h9MRQ2V7gB6YYyUxw",
"version" : {
"number" : "7.9.3",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "c4138e51121ef06a6404866cddc601906fe5c868",
"build_date" : "2020-10-16T10:36:16.141335Z",
"build_snapshot" : false,
"lucene_version" : "8.6.2",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
```
阅读全文