Home > Software > How to Set Up Elasticsearch with Docker Compose

How to Set Up Elasticsearch with Docker Compose

Anastasios Antoniadis

Discover the step-by-step process to set up Elasticsearch using Docker Compose with our expert guide. Enhance your data analysis and search capabilities by effortlessly deploying this robust search engine in your infrastructure.

Docker (1)

Elasticsearch is a powerful open-source search and analytics engine known for its speed, distributed nature, and scalability. It’s widely used for log analytics, full-text search, security intelligence, and operational intelligence use cases. Docker Compose simplifies the deployment of Elasticsearch, allowing you to define and run multi-container Docker applications easily. This guide will walk you through setting up Elasticsearch using Docker Compose, enabling you to index and search data quickly.

Prerequisites

Before starting, ensure you have the following:

  • Docker installed on your system.
  • Docker Compose installed on your system.
  • Basic familiarity with Docker concepts and the YAML syntax used in Docker Compose files.

Step 1: Create a Docker Compose File

First, create a directory dedicated to your Elasticsearch setup. This directory will contain your Docker Compose file (docker-compose.yml) and any additional configuration files or directories you might need.

mkdir elasticsearch-docker && cd elasticsearch-docker

Create the docker-compose.yml file:

touch docker-compose.yml

Open this file in a text editor and insert the following configuration:

version: '3.8'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.12.2
    container_name: elasticsearch
    environment:
      - discovery.type=single-node
    ports:
      - "9200:9200"
    volumes:
      - elasticsearch-data:/usr/share/elasticsearch/data
    networks:
      - elastic

volumes:
  elasticsearch-data:

networks:
  elastic:

Configuration Explained:

  • image: Specifies the Docker image to use. This example uses elasticsearch:8.12.2 from Elastic’s official Docker registry. You can adjust the version number as needed.
  • container_name: Sets a custom name for your container for easier reference.
  • environment: Includes environment variables required by Elasticsearch. discovery.type=single-node configures Elasticsearch to run in a single-node cluster, suitable for development and testing.
  • ports: Exposes port 9200 on the host, mapping it to Elasticsearch’s default port inside the container. This allows you to interact with Elasticsearch via the host machine.
  • volumes: Maps a volume for persistent storage of Elasticsearch data. This ensures that your data is retained across container restarts.
  • networks: Defines a custom network named elastic. This is useful for adding more Elastic Stack components (like Kibana) to the network later.

Step 2: Launch Elasticsearch

With your docker-compose.yml file ready, start Elasticsearch by running:

docker compose up -d

This command will download the necessary Docker image (if not already present) and start the Elasticsearch container in detached mode.

Step 3: Verify Elasticsearch is Running

To confirm that Elasticsearch is up and running, open a web browser or use a tool like curl to send a request to http://localhost:9200. You should receive a response with information about the Elasticsearch cluster, indicating that it’s operational.

Example curl command:

curl http://localhost:9200

Conclusion

Deploying Elasticsearch with Docker Compose offers a straightforward method to get your search and analytics engine running quickly. Following the steps outlined in this guide, you can set up Elasticsearch, ensuring a robust foundation for developing search-driven applications and analyzing data. Docker Compose simplifies the management of Elasticsearch, making it easy to scale and maintain your setup. Whether you’re a developer, data analyst, or DevOps engineer, integrating Elasticsearch into your workflow can unlock powerful capabilities for efficiently processing and analyzing large volumes of data.

Anastasios Antoniadis
Follow me
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x