Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Deploying OpenSearch with Docker for Development and Testing

Tech May 13 1

Overview of OpenSearch

OpenSearch is an open-source, distributed search and analytics suite derived from a fork of Elasticsearch. It supports use cases such as full-text search, log and infrastructure monitoring, security analytics, and operational observability. The project is maintained under the Apache License 2.0 and hosted publicly on GitHub, with active stewardship from AWS.

Pulling Official Images

# Retrieve the latest OpenSearch server image
docker pull opensearchproject/opensearch:latest

# Retrieve the corresponding OpenSearch Dashboards image
docker pull opensearchproject/opensearch-dashboards:latest

Launching a Standalone Node

For local development or evaluation, a single-node cluster can be started with minimal configuration:

docker run \
  --name os-standalone \
  -d \
  -p 9200:9200 \
  -p 9600:9600 \
  -e "discovery.type=single-node" \
  -e "network.host=0.0.0.0" \
  -e "plugins.security.disabled=false" \
  opensearchproject/opensearch:latest

Key environment variables:

  • discovery.type=single-node: Enables single-node mode without cluster coordination.
  • network.host=0.0.0.0: Binds to all interfaces for external acces.
  • plugins.security.disabled=false: Activates the Security plugin (default credentials: admin:admin).

Verifying Connectivity

After startup, confirm the node is responsive using TLS-authenticated curl:

curl -k -u 'admin:admin' https://localhost:9200

The -k flag bypasses certificate validation — appropriate to self-signed dev certificates.

Running OpenSearch Dashboards

Dashboards connect to the OpenSearch backend via HTTPS or HTTP depending on security settings:

# With security enabled (HTTPS + auth)
docker run \
  --name os-dash \
  -d \
  -p 5601:5601 \
  -e "server.host=0.0.0.0" \
  -e 'OPENSEARCH_HOSTS=["https://host.docker.internal:9200"]' \
  opensearchproject/opensearch-dashboards:latest

# With security disabled (HTTP only, no auth)
docker run \
  --name os-dash-insecure \
  -d \
  -p 5601:5601 \
  -e "server.host=0.0.0.0" \
  -e 'OPENSEARCH_HOSTS=["http://host.docker.internal:9200"]' \
  -e "OPENSEARCH_DASHBOARDS_SECURITY_ENABLED=false" \
  opensearchproject/opensearch-dashboards:latest

Note: Use host.docker.internal for host resolution from containers on Docker Desktop. On Linux, replace it with the host’s actual IP or configure DNS accordingly.

Multi-Node Cluster Using Docker Compose

A minimal two-node cluster with Dashboards can be orchestrated via docker-compose.yml:

version: '3.8'

services:
  opensearch-01:
    image: opensearchproject/opensearch:latest
    container_name: opensearch-01
    environment:
      - cluster.name=search-cluster
      - node.name=os-node-1
      - discovery.seed_hosts=opensearch-01,opensearch-02
      - cluster.initial_master_nodes=opensearch-01,opensearch-02
      - bootstrap.memory_lock=true
      - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    ports:
      - "9200:9200"
      - "9600:9600"

  opensearch-02:
    image: opensearchproject/opensearch:latest
    container_name: opensearch-02
    environment:
      - cluster.name=search-cluster
      - node.name=os-node-2
      - discovery.seed_hosts=opensearch-01,opensearch-02
      - cluster.initial_master_nodes=opensearch-01,opensearch-02
      - bootstrap.memory_lock=true
      - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1

  dashboards:
    image: opensearchproject/opensearch-dashboards:latest
    container_name: os-dashboards
    ports:
      - "5601:5601"
    environment:
      - "server.host=0.0.0.0"
      - 'OPENSEARCH_HOSTS=["https://opensearch-01:9200"]'
      - "OPENSEARCH_USERNAME=admin"
      - "OPENSEARCH_PASSWORD=admin"
    depends_on:
      - opensearch-01
      - opensearch-02

This configuration uses internal service names (opensearch-01, opensearch-02) for inter-container communication and assumes TLS is configured or disabled appropriately in production environments.

Observability Considerations

Monitoring OpenSearch containers involves tracking JVM metrics (heap usage, GC frequency), OS-level resource consumption (CPU, memory), and OpenSearch-specific health endpoints (/_cluster/health, /_nodes/stats). For Kubernetes deployments, leverage Prometheus exporters like the OpenSearch Prometheus Exporter alongside standard tooling such as kube-state-metrics and cAdvisor.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.