Elastic Search

How to Install Elasticsearch With Docker?

Elasticsearch is a popular and well-growing search engine and analytical tool. It is frequently used to store and analyze various types of data and information but is usually used for unstructured and semi-structured data. It can be easily set up and installed on different platforms.

Sometimes, users are required to use Elasticsearch with some applications that are based on different platforms such as Ubuntu distribution. In such situations, users can install and use Elasticsearch with Docker. Docker is a platform where users can easily containerize their applications and programs along with required dependencies.

This article will demonstrate the method of installing Elasticsearch with Docker.

How to Install Elasticsearch With Docker?

Docker is a platform where users can execute Elasticsearch in a containerized and isolated environment. To install Elasticsearch with Docker, go through the listed steps.

Step 1: Pull Docker Image

First, pull the Elasticsearch Docker image from the official Docker registry using the “docker pull <image-name>” command:

docker pull docker.elastic.co/elasticsearch/elasticsearch:8.8.2

 

Step 2: Create a Network

Next, create a new network for Elasticsearch using the “docker network create” command. This step is optional but recommended. As creating a network is beneficial in that way when the user removes the container, the Elasticsearch will be completely removed along with the data. But the network will have a backup of Elasticsearch data:

docker network create elastic

 

Step 3: Run the Image

Next, execute the Elasticsearch image to create and start the Elasticsearch container using the below command:

docker run --name es01 --net elastic -p 9200:9200 -it docker.elastic.co/elasticsearch/elasticsearch:8.8.2

 

In the above-mentioned command:

  • –name” option is specifying the container name.
  • –net” option is used to connect the network with the container.
  • -p” option is defining the container’s exposed port.
  • -it” flag is executing the container interactively and allocates the terminal to the container:

Here, Elasticsearch will generate the password for the “elastic” user and token to configure Kibana. Create a backup of this information for later use:

Note: At this point, users may face difficulty in executing the container and may encounter an error “Elasticsearch did not exit normally”. To resolve this issue, you can navigate to our provided solution by following the attached post.

Step 4: Verification

To verify if the container is executing Elasticsearch on the specified port, navigate to the “http://localhost:9200” URL. Upon doing so, Elasticsearch will ask you to enter your username and password. Add the username “elastic” and password that was generated while executing the Elasticsearch container in the above step. The below output show that we have successfully executed the Elasticsearch with the Docker container:

Note: At this point, many users can face the “Connection Was Reset” error. To resolve the stated error, go through our linked article in which we have provided a step-by-step guide to resolve the “Connection Was Reset” error.

That’s all about the installation of Elasticsearch with Docker.

Conclusion

To install Elasticsearch with Docker, first, pull the official Elasticsearch image from the registry using the “docker pull <image-name>” command. After that, execute the image through the “docker run -p 9200:9200 <image-name>” command. This blog has demonstrated the method for installing Elasticsearch with Docker.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.