在Docker中部署Elasticsearch

1、docker 安装部署

#更新 yum 源(一下均为 root 用户)
yum update
#安装 docker
yum remove docker-ce -y && yum install docker-ce -y && service docker start
#docker 启动
systemctl start docker
#docker 设置开机启动
systemctl enable docker
#docker 停止
systemctl stop docker
#有时候需要使用这种命令启动
systemctl start docker.service
systemctl enable docker.service

2、docker 镜像配置

在宿主机器编辑文件:vim /etc/docker/daemon.json

#请在该配置文件中加入(没有该文件的话,请先建一个):
{
  "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
}

 

3、elasticsearch 安装部署

3.1 拉去指定版本镜像

 

#拉取镜像
docker pull elasticsearch:7.7.0
#docker images 命令查看镜像列表 docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
elasticsearch 7.7.0 7ec4f35ab452 15 months ago 757MB

3.2 启动 es

#启动镜像
docker run --name elasticsearch -d -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -e "discovery.type=single-node" -p 9200:9200 -p 9300:9300 elasticsearch:7.7.0

#--name 表示镜像启动后的容器名称
#-d: 后台运行容器,并返回容器 ID;
#-e: 指定容器内的环境变量
#-p: 指定端口映射,格式为:主机(宿主)端口:容器端口


#docker ps 命令查看 es 状态

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3e01cb2b81fb elasticsearch:7.7.0 "/tini -- /usr/local…" 24 minutes ago Up 19 minutes 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch

 

3.3 验证 es 是否成功

浏览器输入 IP:9200

在 Docker 中部署 Elasticsearch

4、docker 常用命令介绍

docker 启动
systemctl start docker

docker 设置开机启动
systemctl enable docker

docker 停止
systemctl stop docker

docker 查看版本
docker version

docker 容器操作
docker ps 查看任务
docker stop 容器 id 停止容器
docker start 容器 Id 启动容器
docker rm 容器 Id 删除容器

更多操作命令

Management Commands:
app* Docker App (Docker Inc., v0.9.1-beta3)
builder Manage builds
buildx* Build with BuildKit (Docker Inc., v0.6.1-docker)
config Manage Docker configs
container Manage containers
context Manage contexts
image Manage images
manifest Manage Docker image manifests and manifest lists
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
scan* Docker Scan (Docker Inc., v0.8.0)
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes

Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container’s changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container’s filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container’s filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes

Run ‘docker COMMAND –help’ for more information on a command.

To get more help with docker, check out our guides at https://docs.docker.com/go/guides/


来源:https://www.jianshu.com/p/68a2aa9f387b

© 版权声明

☆ END ☆
喜欢就点个赞吧
点赞0 分享
图片正在生成中,请稍后...