Create Elasticsearch service with Docker

1. What is Docker?

Docker is an open source tool that encapsulates a web application in a lightweight, portable and independent container, which can then run in almost any service environment.
Docker containers enable applications to run on any server and behave consistently. A container created by a developer on a laptop can run in many environments, such as: test environment, production environment, virtual machine, VPS, OpenStack cluster, public computer, etc.
Docker is generally used in the following points:
• Automated packaging and deployment of applications
• Creation of a lightweight, private PAAS environment
• Automated testing and continuous integration/deployment
• Deployment of web applications, databases and backend services

Therefore, Docker is a system-level compatible container. It uses Linux Container technology to build a virtual environment. Users can install various applications in this environment to provide services, and this environment can be created or destroyed at any time without affecting the host environment.

2. What is Elasticsearch?

Elasticsearch is also developed in Java and uses Lucene as its core for all indexing and searching functionality, but its purpose is to hide the complexity of Lucene through a simple RESTful API, making full-text search easy.

However, Elasticsearch is not just Lucene and full text search, we can describe it this way:
• Distributed real-time file storage, every field is indexed and searchable
• Distributed real-time analytical search engine
• Scalable to Hundreds of servers, processing petabytes of structured or unstructured data

In short, ES is a great search storage engine.

3. Create a Docker image

Elasticsearch has officially provided images on Docker Hub. If there are no additional requirements, you can directly use the images provided by Elasticsearch by executing the following command:

docker run -d -p 9200:9200 --name="es" elasticsearch:2.3.5

To install an additional Elasticsearch head plug-in to facilitate debugging, make an image, Dockerfile

FROM elasticsearch:2.3.5

RUN /usr/share/elasticsearch/bin/plugin install mobz/elasticsearch-head

EXPOSE 9200

Go to the folder where the Dockerfile is located and execute the following command:

docker build --tag=es_ezio:2.3.5 .

Then execute docker images to see the image you just created

# docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
es_ezio                     2.3.5               d66c3f2ed24f        About an hour ago   348.8 MB
docker.io/elasticsearch     2.3.5               1c3e7681c53c        17 months ago       346.4 MB

Fourth, start the container and service

In the previous step we just made a Docker image, not yet created a Docker container. The relationship between images and containers in Docker can be compared to programs and processes in operating systems, or Class and Instance in object-oriented languages. We have to create a container from the image to run our service (aka Elasticsearch service).

To create a Docker container for the first time, execute the following command:

docker run -d -p 9200:9200 --name="es_ezio" es_ezio:2.3.5

The default port of Elasticsearch is 9200. We map the host environment 9200 to port 9200 in the Docker container, so that we can directly access the 9200 port of the host environment to access the Elasticsearch service in the Docker container, and we name the container. for es_ezio.

If all goes well, visit  http://127.0.0.1:9200/_plugin/head/

In this way, we have completed using Docker to provide Elasticsearch services without polluting the host environment. This has another advantage. If you want to start multiple different versions of Elastcsearch or other services at the same time, Docker is also an ideal solution.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324957542&siteId=291194637