Skip to content

Instantly share code, notes, and snippets.

@khansun
Last active August 15, 2026 10:53
Show Gist options
  • Select an option

  • Save khansun/65d4aca990bb402785502d05183d3b38 to your computer and use it in GitHub Desktop.

Select an option

Save khansun/65d4aca990bb402785502d05183d3b38 to your computer and use it in GitHub Desktop.
ELK-APM

Standalone Elastic Stack (ELK + APM) 8.13.0 - Docker Compose

A fully functional, secure ELK stack setup (Elasticsearch, Logstash, Kibana, APM-Server) for local development.

  1. Prerequisites (Linux Host) If running on Linux, increase the virtual memory map count, otherwise, Elasticsearch will fail to boot:
  • Optional sudo sysctl -w vm.max_map_count=262144
  1. Logstash Pipeline (logstash/pipeline/logstash.conf)
input {
  # Standard input for Filebeat/Metricbeat
  beats {
    port => 5044
  }
  # Simple HTTP input for easy testing via cURL
  http {
    host => "0.0.0.0"
    port => 8080
  }
}

output {
  elasticsearch {
    hosts => ["http://elasticsearch:9200"]
    index => "logstash-%{+YYYY.MM.dd}"
  }
  # Prints the logs to the docker terminal for debugging
  stdout { 
    codec => rubydebug 
  }
}

  1. Docker Compose (docker-compose.yml) Includes a setup container that handles the automated security configuration and password setting for you.
version: "3.8"

services:
  # This container simply runs a quick API call to configure the kibana_system user, then exits.
  setup:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.13.0
    container_name: setup
    depends_on:
      - elasticsearch
    command: >
      bash -c '
        echo "Waiting for Elasticsearch to start...";
        until curl -s -u elastic:changeme http://elasticsearch:9200 | grep -q "cluster_name"; do
          sleep 5;
        done;
        echo "Setting kibana_system password...";
        curl -s -X POST -u elastic:changeme -H "Content-Type: application/json" http://elasticsearch:9200/_security/user/kibana_system/_password -d "{\"password\":\"changeme\"}";
        echo "Setup complete!";
      '
    networks:
      - elk

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.13.0
    container_name: elasticsearch
    environment:
      - node.name=elasticsearch
      - discovery.type=single-node
      - xpack.security.enabled=true
      - xpack.security.http.ssl.enabled=false
      - xpack.security.transport.ssl.enabled=false
      - ELASTIC_PASSWORD=changeme
      - ES_JAVA_OPTS=-Xms2g -Xmx2g
    ports:
      - "9200:9200"
      - "9300:9300"
    volumes:
      - esdata:/usr/share/elasticsearch/data
    networks:
      - elk

  kibana:
    image: docker.elastic.co/kibana/kibana:8.13.0
    container_name: kibana
    depends_on:
      setup:
        condition: service_completed_successfully
      elasticsearch:
        condition: service_started
    environment:
      - ELASTICSEARCH_HOSTS=http://elasticsearch:9200
      - ELASTICSEARCH_USERNAME=kibana_system 
      - ELASTICSEARCH_PASSWORD=changeme
      # Required by Fleet to install Integrations
      - XPACK_ENCRYPTEDSAVEDOBJECTS_ENCRYPTIONKEY=YourSuperSecret32CharacterKeyHere123! 
    ports:
      - "5601:5601"
    networks:
      - elk

  logstash:
    image: docker.elastic.co/logstash/logstash:8.13.0
    container_name: logstash
    depends_on:
      - elasticsearch
    ports:
      - "5044:5044"
      - "9600:9600"
      - "8080:8080"
    volumes:
      - ./logstash/pipeline:/usr/share/logstash/pipeline
    environment:
      - LS_JAVA_OPTS=-Xms1g -Xmx1g
    networks:
      - elk

  apm-server:
    image: docker.elastic.co/apm/apm-server:8.13.0
    container_name: apm-server
    depends_on:
      - elasticsearch
      - kibana
    command: >
      apm-server -e
      -E apm-server.host=0.0.0.0:8200
      -E output.elasticsearch.hosts=["http://elasticsearch:9200"]
      -E output.elasticsearch.username=elastic
      -E output.elasticsearch.password=changeme
      -E setup.kibana.host=http://kibana:5601
      -E setup.kibana.protocol=http
      -E setup.kibana.username=elastic
      -E setup.kibana.password=changeme
    ports:
      - "8200:8200"
    networks:
      - elk

volumes:
  esdata:

networks:
  elk:
    driver: bridge
    
  1. Running the stack Start the stack: docker compose up -d

Wait for setup container to exit.

Access Kibana: http://localhost:5601

Login: Use Username elastic and Password changeme.

Install APM: Navigate to Management > Integrations, search for APM, and click Add Elastic APM to install the required index templates.

  1. Onboard your JAVA application (apm.jar required in path) using the folling ENV config
OTEL_JAVA_GLOBAL_AUTOCONFIGURE_ENABLED=true
JAVA_TOOL_OPTIONS=-javaagent:../apm.jar
ELASTIC_APM_SERVICE_NAME=my-app
ELASTIC_APM_SERVER_URLS=http://localhost:8200
ELASTIC_APM_ENVIRONMENT=local
ELASTIC_APM_APPLICATION_PACKAGES=com.myapp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment