Installing elasticsearch in docker

1. Change docker image warehouse

# There are a lot of them on the Internet. I also found them on the Internet, or I went to Alibaba cloud to apply for them
vi /etc/docker/daemon.json
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
# Restart docker
systemctl restart docker.service

2. You can first see which containers are there

docker images

3. View running and not running containers

docker ps is running
 Docker PS-A running and not running

4. Pull image from central warehouse

# Version number is required
docker pull elasticsearch:7.4.2
# This command is an elastic search graphical interface. I didn't install it because I felt it was a little slow~
docker pull kibana:7.4.2
# Create a directory to store data
mkdir -p /mydata/elasticsearch/config
mkdir -p /mydata/elasticsearch/data
# It can be accessed by any Internet
echo "http.host: 0.0.0.0" >> /mydata/elasticsearch/config/elasticsearch.yml
# Check whether the creation is successful

5. Run the container in the background and map the configuration file

# -E es ﹣ Java ﹣ opts = "- xms64m - xmx128m" \ it must be added, so that memory is not the only thing.... 64-128m is enough for self-study and test, at least 32G for the company
docker run --name elasticsearch2 -p 9200:9200 -p 9300:9300 \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms64m -Xmx128m" \
-v /mydata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /mydata/elasticsearch/data:/usr/share/elasticsearch/data \
-v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-d elasticsearch:7.4.2

6. Check whether the startup is successful

docker ps

According to your own IP and 9200 port access

It may fail at this time. You can use docker logs < container ID > to view the operation log
If you do not have read-write permission for permission issues, you can use chmod -R 777 /mydata/elasticsearch / to modify the permissions of elasticsearch
Then it's ok... If there are other problems, you need to check them carefully and slowly, such as the details of where there are fewer spaces and line breaks

Finally, we attach some common docker commands

#1. Stop all container s to delete the images:
docker stop $(docker ps -a -q)
2.If you want to delete all container Add another instruction:
docker rm $(docker ps -a -q)
#3. View the current images
docker images
#4. Delete images. Specify who to delete by the image id
docker rmi <image id>
#5. To delete untagged images, that is, images with id < none > can be used
docker rmi $(docker images | grep "^<none>" | awk "{print $3}")
#6. To delete all image s
docker rmi $(docker images -q)

Tags: Java Docker ElasticSearch JSON

Posted on Sat, 09 May 2020 11:22:27 -0400 by skyxmen