Installing Elastic Search 7.14 with docker

WHAT TO KNOW - Sep 10 - - Dev Community

Installing Elasticsearch 7.14 with Docker

Elasticsearch logo

Introduction

Elasticsearch is a powerful, open-source, distributed search and analytics engine built on Apache Lucene. It offers real-time search capabilities, data analysis, and storage for diverse datasets. Docker, a platform for containerizing applications, provides a convenient way to deploy and manage Elasticsearch instances.

This article delves into the process of installing Elasticsearch 7.14 using Docker. We will cover the essential concepts, practical steps, and best practices to ensure a seamless and efficient setup.

Why Use Docker for Elasticsearch?

Deploying Elasticsearch with Docker brings several advantages:

  • Isolation and Portability: Docker containers isolate Elasticsearch from the host system, ensuring a consistent environment across different machines. This portability allows for easy deployment on various platforms.
  • Simplified Management: Docker simplifies the management of Elasticsearch instances, including starting, stopping, and scaling.
  • Version Control: Docker images encapsulate specific Elasticsearch versions, facilitating version management and ensuring compatibility.
  • Resource Optimization: Docker provides resource isolation and control, enabling efficient resource allocation for Elasticsearch.

    Prerequisites

    Before you start, ensure you have the following:

  • Docker installed: Download and install Docker from the official website: https://www.docker.com/products/docker-desktop/

  • Docker Compose (optional): Docker Compose simplifies multi-container deployments and is recommended for Elasticsearch clusters. Install it with the following command:

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Enter fullscreen mode Exit fullscreen mode

Steps to Install Elasticsearch 7.14 with Docker

We will cover two approaches:

  1. Single Node Installation (using Docker run command)
  2. Multi-Node Cluster Installation (using Docker Compose)

    1. Single Node Installation


    This approach is suitable for testing or small deployments.


  • Pull the Image: Download the official Elasticsearch 7.14 Docker image:

  • docker pull elasticsearch:7.14.0
    
    Enter fullscreen mode Exit fullscreen mode
    1. Run the Container: Start an Elasticsearch instance with the following command:
    docker run -d -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "bootstrap.memory_lock=true" -e "xpack.security.enabled=false" elasticsearch:7.14.0
    
    Enter fullscreen mode Exit fullscreen mode

    Explanation of Flags:

    • -d: Runs the container in detached mode (background).
    • -p 9200:9200: Maps port 9200 on the host to port 9200 inside the container (default HTTP port for Elasticsearch).
    • -p 9300:9300: Maps port 9300 on the host to port 9300 inside the container (default transport port for Elasticsearch).
    • -e "discovery.type=single-node": Configures Elasticsearch to operate as a single-node instance.
    • -e "bootstrap.memory_lock=true": Allows Elasticsearch to lock its memory for performance optimization.
    • -e "xpack.security.enabled=false": Disables X-Pack security for simplicity.
    1. Verify Installation: Access the Elasticsearch API by opening a web browser and navigating to: http://localhost:9200/. You should see a JSON response indicating that Elasticsearch is running.

      1. Multi-Node Cluster Installation


      This approach is ideal for production environments or deployments requiring high availability.


  • Create a Docker Compose File: Create a file named docker-compose.yml with the following configuration:

  • version: "3.7"
    
    services:
      elasticsearch:
        image: elasticsearch:7.14.0
        ports:
          - "9200:9200"
          - "9300:9300"
        environment:
          - "discovery.type=single-node"
          - "bootstrap.memory_lock=true"
          - "xpack.security.enabled=false"
        ulimits:
          memlock:
            soft: -1
            hard: -1
        volumes:
          - elasticsearch-data:/usr/share/elasticsearch/data
      kibana:
        image: kibana:7.14.0
        ports:
          - "5601:5601"
        depends_on:
          - elasticsearch
        environment:
          - ELASTICSEARCH_HOSTS=elasticsearch:9200
    
    volumes:
      elasticsearch-data:
    
    
    Enter fullscreen mode Exit fullscreen mode

    Explanation:

    • elasticsearch service: Defines the Elasticsearch container, including image, ports, environment variables, and data volume mounting.
    • kibana service: Defines the Kibana container, which depends on Elasticsearch and connects to it.
    • volumes: Creates a volume named elasticsearch-data for persistent data storage.
    1. Start the Cluster: Run the following command to start the containers defined in docker-compose.yml:
    docker-compose up -d
    
    Enter fullscreen mode Exit fullscreen mode
    1. Verify Installation: Open a web browser and navigate to http://localhost:5601/. Kibana should connect to the Elasticsearch cluster, providing a visual interface for managing and analyzing data.

      Additional Configuration Options

    2. Network Configuration: For large clusters, consider using a dedicated network for communication between Elasticsearch nodes. You can achieve this by defining a custom Docker network in the docker-compose.yml file.
    3. X-Pack Security: For production deployments, enable X-Pack security to secure your Elasticsearch cluster. You can configure X-Pack in the docker-compose.yml file or through environment variables.
    4. Data Storage: For persistent data storage, mount a volume to the Elasticsearch container. This ensures data persistence even after the container is restarted.
    5. Plugins: Elasticsearch offers various plugins to extend its functionality. You can install plugins either during container creation or by updating the container after it's running.

      Troubleshooting

    6. Connection Issues: Ensure that the host ports (9200 and 9300) are not blocked by firewalls.
    7. Data Persistence: If data is not being saved, check if the volume is correctly mounted.
    8. Cluster Formation: Ensure that the discovery.type setting is correctly configured for the cluster setup.
    9. Logs: Examine the Elasticsearch logs inside the container for error messages.

      Conclusion

      Installing Elasticsearch 7.14 with Docker is a straightforward process that provides significant benefits for deploying, managing, and scaling Elasticsearch instances. This guide has covered the essential steps, concepts, and configurations to set up both single-node and multi-node Elasticsearch deployments using Docker. Remember to leverage Docker's features for isolation, portability, and efficient resource management to create robust and scalable Elasticsearch environments.
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    Terabox Video Player