PortGate

Blueprints · Docker & Databases

Production 15 min · Elasticsearch

Elasticsearch localhost bind

Publishes Elasticsearch only on 127.0.0.1 and turns off the single-node HTTP free-for-all by keeping the port off the public interface.

Why this should not be public

A reachable Elasticsearch lets anyone list indices and download documents, and it is behind many of the largest accidental data leaks. Older versions also allowed code execution through scripting (CVE-2015-1427).

Live config

Baked-in protections

Step 1 · yaml

Compose file

/opt/elasticsearch/compose.yaml

Memory lock is left off so a small VPS can start the container. Add the security settings from Elastic before other hosts query this node.

services:
  elasticsearch:
    image: elasticsearch:8.15.0
    environment:
      discovery.type: single-node
      xpack.security.enabled: "true"
      ES_JAVA_OPTS: -Xms512m -Xmx512m
      network.host: 0.0.0.0
    ports:
      - "127.0.0.1:9200:9200"
    mem_limit: 1g
    security_opt:
      - no-new-privileges:true
    restart: unless-stopped

Step 2 · bash

Start script

/opt/elasticsearch/up.sh

Written, not run. Set the elastic password on first boot with the reset tool inside the container.

#!/bin/sh
set -eu
cd "/opt/elasticsearch"
docker compose up -d