composebuilder

Docker Compose: Elasticsearch 8 + Kibana Search Stack

Docker Compose stack for Elasticsearch 8.19 and Kibana 8.19 with security enabled, a persistent volume, a healthcheck and localhost-only ports.

When to use this stack

Elasticsearch is a distributed search and analytics engine built on Apache Lucene. It handles full-text search, log analysis and aggregations over large document collections, and Kibana is its official web interface for exploring data, building dashboards and managing security. This stack runs Elasticsearch 8.19 with security enabled, a single-node discovery setting, a heap limit and a persistent volume, plus Kibana 8.19 connected through the kibana_system account. The result is a working search and log analysis environment on one server.

Use this stack for log search, a document index behind an application, or a prototype of an analytics pipeline that will later grow beyond one node. Do not run it casually. Elasticsearch needs careful memory, disk and security configuration, and a single node has no redundancy. The sample turns off HTTP TLS only because the containers talk on an internal network, and it keeps both ports bound to localhost. Enable TLS, create per-application users and plan snapshots before you put any production data in it.

docker-compose.yml

services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.19.25
    restart: unless-stopped
    environment:
      discovery.type: single-node
      cluster.name: ${ES_CLUSTER_NAME}
      ELASTIC_PASSWORD: ${ELASTIC_PASSWORD}
      xpack.security.enabled: "true"
      xpack.security.http.ssl.enabled: "false"
      ES_JAVA_OPTS: "-Xms1g -Xmx1g"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    mem_limit: 2g
    volumes:
      - es_data:/usr/share/elasticsearch/data
    ports:
      - "127.0.0.1:9200:9200"
    healthcheck:
      test: ["CMD-SHELL", "curl -fs -u elastic:$$ELASTIC_PASSWORD http://127.0.0.1:9200/_cluster/health || exit 1"]
      interval: 15s
      timeout: 10s
      retries: 10
      start_period: 60s

  kibana:
    image: docker.elastic.co/kibana/kibana:8.19.25
    restart: unless-stopped
    environment:
      ELASTICSEARCH_HOSTS: http://elasticsearch:9200
      ELASTICSEARCH_USERNAME: kibana_system
      ELASTICSEARCH_PASSWORD: ${KIBANA_SYSTEM_PASSWORD}
    ports:
      - "127.0.0.1:5601:5601"
    depends_on:
      elasticsearch:
        condition: service_healthy

volumes:
  es_data:

.env

.env
# Cluster name shown in Elasticsearch and Kibana
ES_CLUSTER_NAME=local-cluster

# Password of the built-in elastic superuser, set on the first start
ELASTIC_PASSWORD=CHANGE_ME_ELASTIC_PASSWORD

# Password of the kibana_system account, set through the security API below
KIBANA_SYSTEM_PASSWORD=CHANGE_ME_KIBANA_SYSTEM_PASSWORD

Start and verify

Elasticsearch needs a higher memory map limit on Linux hosts. Docker Desktop on Windows handles this inside its WSL 2 backend. The order matters: start Elasticsearch first, set the kibana_system password through the API, and only then start Kibana.

Shell
sudo sysctl -w vm.max_map_count=262144
set -a; . ./.env; set +a
docker compose config --quiet
docker compose up -d elasticsearch
until docker compose exec -T elasticsearch curl -fs -u "elastic:$ELASTIC_PASSWORD" http://127.0.0.1:9200/_cluster/health >/dev/null 2>&1; do sleep 5; done
curl -s -u "elastic:$ELASTIC_PASSWORD" -X POST http://127.0.0.1:9200/_security/user/kibana_system/_password -H "Content-Type: application/json" -d "{\"password\":\"$KIBANA_SYSTEM_PASSWORD\"}"
docker compose up -d kibana
docker compose ps
docker compose logs --tail=30 kibana
curl -s -u "elastic:$ELASTIC_PASSWORD" "http://127.0.0.1:9200/_cluster/health?pretty"

The password call should return a short JSON success response. The cluster health should eventually report green or yellow. Kibana then becomes reachable at http://127.0.0.1:5601 through the SSH tunnel or the local browser.

Production checklist

  • Replace every CHANGE_ME value with a long random password, and do not use the elastic superuser in applications.
  • Enable TLS for the HTTP and transport layers with certificates from your own CA, and remove the disabled setting from the sample.
  • Create per-application users with the smallest roles that work, and rotate their passwords on a schedule.
  • Keep ports 9200 and 5601 on localhost, or put them behind a TLS proxy with single sign-on or VPN access.
  • Set the heap to about half of the container memory, and never above 31 GB.
  • Define index lifecycle policies for log indexes, so old data is rolled over and deleted before the disk fills.
  • Watch the disk watermarks, because Elasticsearch blocks writes when the disk is nearly full.
  • Register a snapshot repository, take regular snapshots and test a restore into a separate cluster.

Common problems

  • Symptom: Elasticsearch stops with a message about the max virtual memory areas limit. Cause: the host kernel setting vm.max_map_count is below 262144. Fix: run sudo sysctl -w vm.max_map_count=262144, and persist the value in /etc/sysctl.conf.

  • Symptom: Kibana restarts repeatedly and logs an authentication error for kibana_system. Cause: the kibana_system password was not set, or it was set after Kibana had already started. Fix: run the password request from the start section, then run docker compose restart kibana.

  • Symptom: the cluster health stays red after a restart. Cause: the data directory is not writable, or the disk is above the flood stage watermark. Fix: check docker compose logs elasticsearch for watermark messages, free disk space, and make sure the volume is mounted.

  • Symptom: the elastic login fails after you change ELASTIC_PASSWORD in .env. Cause: the variable is used only on the first start of the data volume. Fix: reset the password inside the container with bin/elasticsearch-reset-password -u elastic -a, then update your records.

Variations

  • OpenSearch instead: OpenSearch is a fork with its own images and dashboards. The layout is similar, but the image names and environment variables differ.
  • Development without security: setting xpack.security.enabled to false is possible for a throwaway local test. Never use it on a server that is reachable from other machines.
  • Log shipping: add Filebeat or Logstash on the same network to send container logs into Elasticsearch through an application user with write-only rights.

Questions

Why does Elasticsearch exit with a max virtual memory areas error?

Linux needs vm.max_map_count set to at least 262144 on the host. Run sudo sysctl -w vm.max_map_count=262144 and add the same line to /etc/sysctl.conf so it survives a reboot.

Why does Kibana fail to authenticate as kibana_system?

Kibana connects with the kibana_system user, whose password must be set through the security API before Kibana starts. The steps below set it and then restart Kibana.

Do I need TLS for this stack?

Traffic between the containers stays on the internal Compose network, so this sample turns off HTTP TLS to keep the first setup simple. Enable TLS before you expose the ports beyond localhost.

How much RAM does the stack need?

The Elasticsearch heap is set to 1 GB, and the container limit is 2 GB to leave room for the operating system and off-heap memory. Increase both for larger indexes.

Adapt this stack

Load these files into the builder to rename services, change ports, add a cache or a proxy, and generate fresh passwords for the .env.

Open in builder
  • ClickHouse 25.8 Analytics Database

    Docker Compose stack for ClickHouse 25.8 with a dedicated user, a healthcheck, raised file limits and HTTP and native ports on localhost for analytical queries.

    • clickhouse
    Difficulty: Advanced
  • FastAPI + MongoDB 7 + Mongo Express

    Docker Compose stack for a Python FastAPI API on MongoDB 7 with authentication, a healthcheck, persistent storage and a protected Mongo Express UI on localhost.

    • api
    • mongodb
    • mongo-express
    Difficulty: Intermediate
  • MariaDB 11.4 LTS + Adminer 5

    Docker Compose stack with MariaDB 11.4 LTS, a healthcheck, a named volume and Adminer 5 on localhost. A lightweight admin UI for MySQL-compatible databases.

    • mariadb
    • adminer
    Difficulty: Beginner
  • Meilisearch v1 + Python FastAPI Search API

    Docker Compose stack for Meilisearch v1 in production mode with a master key, a healthcheck and persistent data, plus a FastAPI search API on localhost.

    • meilisearch
    • api
    Difficulty: Intermediate

Browse more Databases & Search stacks or the full library.