Home > Software > How to Deploy OpenSearch with Docker Compose: A Comprehensive Guide

How to Deploy OpenSearch with Docker Compose: A Comprehensive Guide

Anastasios Antoniadis

Explore the steps to deploy OpenSearch using Docker Compose in our detailed guide. Unlock powerful search and analytics capabilities for your applications with ease, ensuring scalable and efficient data handling.

Docker (1)

OpenSearch is a community-driven, open-source search and analytics suite derived from Elasticsearch and Kibana. It’s designed for horizontal scalability, reliability, and real-time search capabilities, making it a powerful tool for managing large volumes of data. Deploying OpenSearch using Docker Compose simplifies the setup process, enabling developers and system administrators to quickly set up a search cluster for development, testing, or production environments. This guide will walk you through deploying OpenSearch and OpenSearch Dashboards using Docker Compose.

Prerequisites

Before you start, ensure you have:

  • Docker installed on your system.
  • Docker Compose installed on your system.
  • Basic knowledge of Docker, Docker Compose, and YAML syntax.

Step 1: Create a Docker Compose File

Create a new directory for your OpenSearch project. This directory will contain your Docker Compose file (docker-compose.yml) and any additional configuration files or scripts you might need.

mkdir opensearch-docker && cd opensearch-docker

Create the docker-compose.yml file:

touch docker-compose.yml

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

version: '3.7'

services:
  opensearch:
    image: opensearchproject/opensearch:latest
    container_name: opensearch
    environment:
      - cluster.name=opensearch-cluster
      - node.name=opensearch-node1
      - discovery.seed_hosts=opensearch
      - cluster.initial_master_nodes=opensearch-node1
      - bootstrap.memory_lock=true
      - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - opensearch-data:/usr/share/opensearch/data
    ports:
      - "9200:9200"
      - "9300:9300"
    networks:
      - opensearch-net

  opensearch-dashboards:
    image: opensearchproject/opensearch-dashboards:latest
    container_name: opensearch-dashboards
    ports:
      - "5601:5601"
    expose:
      - "5601"
    environment:
      - OPENSEARCH_HOSTS=http://opensearch:9200
    networks:
      - opensearch-net

volumes:
  opensearch-data:

networks:
  opensearch-net:

Configuration Details:

  • OpenSearch service: Configures an OpenSearch node with essential settings for cluster name, node name, initial master nodes, and memory settings. It also sets ulimits for memory lock.
  • OpenSearch Dashboards service: Sets up OpenSearch Dashboards to connect to your OpenSearch cluster at http://opensearch:9200.
  • Volumes: Uses a named volume (opensearch-data) to persist OpenSearch data.
  • Networks: Defines a custom network (opensearch-net) for inter-service communication within Docker.

Step 2: Launch the OpenSearch Cluster

With your docker-compose.yml file ready, start the OpenSearch cluster by running:

docker compose up -d

This command pulls the necessary Docker images and starts the OpenSearch and OpenSearch Dashboards containers in detached mode.

Step 3: Verify the Deployment

After the services start, verify that OpenSearch is running correctly by querying the cluster status:

curl http://localhost:9200/_cluster/health?pretty

This command should return a JSON response with the cluster health status.

Similarly, ensure OpenSearch Dashboards is accessible by navigating to http://localhost:5601 in a web browser. You should see the OpenSearch Dashboards interface, where you can explore your data.

Step 4: Configuring OpenSearch (Optional)

You’ll likely need to customize your OpenSearch configuration further for production environments. You can do this by mounting a custom opensearch.yml file into your container:

    volumes:
      - ./config/opensearch.yml:/usr/share/opensearch/config/opensearch.yml

Ensure you create the config directory and the opensearch.yml file with your desired configurations.

Conclusion

Deploying OpenSearch with Docker Compose offers a straightforward method for setting up a powerful search and analytics environment. Following the steps outlined in this guide, you can quickly get an OpenSearch cluster up and running, ready for development, testing, or production use. Docker Compose simplifies the management of OpenSearch and OpenSearch Dashboard services, making it easy to scale and maintain your search infrastructure.

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