Home Server › Containers

Centralized homelab container logging with Docker ELK stack

Build a lightweight Docker ELK stack for homelab container logs with single-node Elasticsearch heap tuning, Filebeat, Logstash, Kibana, and 7-day ILM policies.

Centralized homelab container logging with Docker ELK stack

Tailing logs across half a dozen docker logs -f terminals falls apart the moment a container recreates or an error spans multiple services. This post covers deploying a memory-capped Docker ELK stack (Elasticsearch, Logstash, Kibana, and Filebeat) for a homelab, tuning JVM heaps and Linux kernel limits, and automating 7-day log cleanup with ILM.

Tested with Elastic Stack 8.15.2 (Elasticsearch, Logstash, Kibana, Filebeat) on Docker Compose.

Why docker logs stops scaling in a homelab

Once a homelab grows past a few containers—Spring Boot APIs, MariaDB, Redis, Nginx Proxy Manager, and background workers—debugging with docker logs -f <container> hits three walls fast:

  1. Logs vanish on recreate: When a container crashes and gets recreated (docker compose down && up), the previous stdout log disappears with the old container unless you shipped it elsewhere.
  2. No cross-service timeline: Correlating a 502 Bad Gateway in Nginx Proxy Manager with a NullPointerException in a Spring Boot container across separate terminal windows is slow and error-prone.
  3. No full-text search: Grepping through thousands of unstructured lines for a specific trace ID or error message doesn’t hold up during an incident.

To centralize container stdout/stderr in one searchable store, I run a single-node ELK + Filebeat pipeline:

flowchart TD
    subgraph Host["Homelab Containers"]
        APPS["Spring Boot, NPM, MariaDB, Redis"]
        LOGS[("Docker JSON Logs (/var/lib/docker/containers)")]
    end

    subgraph Pipeline["Collection & Indexing"]
        FB["Filebeat (Container log shipper)"]
        LS["Logstash (:5044 / Parse & enrich)"]
        ES[("Elasticsearch (Single node / 1GB heap)")]
    end

    subgraph Access["Search UI"]
        KB["Kibana (:5601)"]
        NPM["Nginx Proxy Manager (kibana.namju.kim)"]
    end

    APPS -->|"stdout / stderr"| LOGS
    LOGS -->|"Read-only mount"| FB
    FB -->|"Beats protocol"| LS
    LS -->|"Structured JSON"| ES
    KB -->|"REST API"| ES
    NPM -->|"HTTPS proxy"| KB

When shouldn’t you run ELK on a homelab? Even tuned down, Elasticsearch + Logstash + Kibana will claim roughly 2.5–3 GB of RAM. If your host only has 4–8 GB of memory, Grafana Loki with Promtail (or Alloy) is a much lighter fit. On a 16 GB+ host where you want full-text search and KQL filtering, a capped ELK stack works well.

Tuning Elasticsearch and Logstash for homelab RAM

Out of the box, Elasticsearch assumes a multi-node production cluster and happily claims 4–8 GB of RAM. To coexist peacefully with your other homelab services, lock down three settings before starting anything.

1. Single-node discovery (discovery.type=single-node)

Disables master election and replica shard overhead so Elasticsearch boots cleanly as a standalone node without complaining about yellow unassigned replicas.

2. Fixed JVM heap limits

  • Elasticsearch (ES_JAVA_OPTS="-Xms1g -Xmx1g"): A 1 GB heap handles homelab container log volumes without trouble. Setting -Xms and -Xmx to the same value prevents heap-resizing pauses during GC.
  • Logstash (LS_JAVA_OPTS="-Xms512m -Xmx512m"): 512 MB is enough for Beats ingestion and light JSON filtering at homelab traffic levels.

3. Linux kernel vm.max_map_count

Elasticsearch uses memory-mapped files (mmap) for indices and refuses to boot if the host’s map count limit is too low. Raise it on your Linux host and persist it across reboots:

1
2
3
4
5
# Apply immediately on the host
sudo sysctl -w vm.max_map_count=262144

# Persist across reboots
echo "vm.max_map_count=262144" | sudo tee -a /etc/sysctl.conf

Docker Desktop on macOS handles vm.max_map_count inside its Linux VM automatically, but bare-metal Linux homelab hosts don’t. Skipping this step causes Elasticsearch to exit immediately with max virtual memory areas vm.max_map_count [65530] is too low.

Logstash pipeline and Filebeat configuration

Filebeat tails Docker’s container log files on disk, attaches Docker metadata (container name, image, labels), and ships events to Logstash over port 5044. Logstash normalizes the fields and writes daily indices to Elasticsearch.

logstash/pipeline/logstash.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# logstash/pipeline/logstash.conf
input {
  beats {
    port => 5044
  }
}

filter {
  # Promote container name to a top-level service_name field
  if [container][image][name] {
    mutate {
      add_field => { "service_name" => "%{[container][name]}" }
    }
  }

  # Parse ISO8601 timestamps into @timestamp
  date {
    match => [ "timestamp", "ISO8601" ]
    target => "@timestamp"
  }
}

output {
  elasticsearch {
    hosts => ["http://elasticsearch:9200"]
    index => "homelab-docker-logs-%{+YYYY.MM.dd}"
    user => "elastic"
    password => "${ELASTIC_PASSWORD}"
  }
}

filebeat/filebeat.yml

1
2
3
4
5
6
7
8
9
10
11
# filebeat/filebeat.yml
filebeat.inputs:
  - type: container
    paths:
      - /var/lib/docker/containers/*/*.log
    processors:
      - add_docker_metadata:
          host: "unix:///var/run/docker.sock"

output.logstash:
  hosts: ["logstash:5044"]

Complete Docker Compose stack

Organize the ELK stack in its own directory:

1
2
3
4
5
6
7
8
~/homelab-elk/
├── .env
├── docker-compose.yml
├── filebeat/
│   └── filebeat.yml
└── logstash/
    └── pipeline/
        └── logstash.conf

Environment file (.env)

1
2
3
4
5
6
7
# .env
ELASTIC_VERSION=8.15.2
ELASTIC_PASSWORD=replace_with_strong_elastic_password
KIBANA_PASSWORD=replace_with_strong_kibana_password
ES_PORT=9200
KIBANA_PORT=5601
TZ=Asia/Seoul

docker-compose.yml

Notice that Elasticsearch (9200) and Logstash (5044) bind strictly to 127.0.0.1 so neither port is exposed on your LAN, while Filebeat mounts /var/lib/docker/containers and /var/run/docker.sock read-only:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# docker-compose.yml
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:${ELASTIC_VERSION:-8.15.2}
    container_name: elk-elasticsearch
    restart: unless-stopped
    environment:
      - node.name=homelab-es01
      - cluster.name=homelab-logs
      - discovery.type=single-node
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms1g -Xmx1g"
      - ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
      - xpack.security.enabled=true
      - xpack.security.http.ssl.enabled=false # Simplified for internal Docker bridge traffic
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65535
        hard: 65535
    ports:
      - "127.0.0.1:${ES_PORT:-9200}:9200" # Bind to host loopback only
    volumes:
      - es_data:/usr/share/elasticsearch/data
    networks:
      - logging-net

  logstash:
    image: docker.elastic.co/logstash/logstash:${ELASTIC_VERSION:-8.15.2}
    container_name: elk-logstash
    restart: unless-stopped
    environment:
      - "LS_JAVA_OPTS=-Xms512m -Xmx512m"
      - ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
    volumes:
      - ./logstash/pipeline/logstash.conf:/usr/share/logstash/pipeline/logstash.conf:ro
    ports:
      - "127.0.0.1:5044:5044"
    networks:
      - logging-net
    depends_on:
      - elasticsearch

  kibana:
    image: docker.elastic.co/kibana/kibana:${ELASTIC_VERSION:-8.15.2}
    container_name: elk-kibana
    restart: unless-stopped
    environment:
      - SERVER_NAME=kibana.namju.kim
      - ELASTICSEARCH_HOSTS=http://elasticsearch:9200
      - ELASTICSEARCH_USERNAME=elastic
      - ELASTICSEARCH_PASSWORD=${ELASTIC_PASSWORD}
      - I18N_LOCALE=en-US
    ports:
      - "${KIBANA_PORT:-5601}:5601"
    networks:
      - logging-net
    depends_on:
      - elasticsearch

  filebeat:
    image: docker.elastic.co/beats/filebeat:${ELASTIC_VERSION:-8.15.2}
    container_name: elk-filebeat
    user: root # Required to read /var/lib/docker/containers logs
    restart: unless-stopped
    volumes:
      - ./filebeat/filebeat.yml:/usr/share/filebeat/filebeat.yml:ro
      - /var/lib/docker/containers:/var/lib/docker/containers:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - logging-net
    depends_on:
      - logstash

volumes:
  es_data:
    name: homelab_es_data

networks:
  logging-net:
    name: homelab_logging_net
    driver: bridge

Bring up the entire stack:

1
docker compose up -d

Reverse proxy and timeout tuning in Nginx Proxy Manager

Expose Kibana at https://kibana.namju.kim via Nginx Proxy Manager:

  • Domain Names: kibana.namju.kim
  • Scheme: http
  • Forward Hostname / IP: your host’s LAN IP
  • Forward Port: 5601
  • Block Common Exploits: ON
  • Websockets Support: ON
  • SSL: select your *.namju.kim wildcard certificate and enable Force SSL and HTTP/2 Support.

Extending Nginx timeouts for heavy searches

Aggregating several days of logs in Kibana can take longer than Nginx’s default 60-second proxy timeout, returning a 504 Gateway Timeout. Open the proxy host’s Advanced tab and add:

1
2
3
4
proxy_read_timeout 300s;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
client_max_body_size 50M;

Creating a Kibana Data View and 7-day ILM policy

Once Kibana finishes booting, open https://kibana.namju.kim and sign in with elastic and your ${ELASTIC_PASSWORD}.

Register the Data View

  1. Go to Management > Stack Management > Data Views (formerly Index Patterns).
  2. Click Create data view:
    • Name: Homelab Containers
    • Index pattern: homelab-docker-logs-*
    • Timestamp field: @timestamp
  3. Save and switch to Analytics > Discover.

Every container’s stdout now lands in one timeline. You can filter instantly with KQL queries like service_name: "spring-app" and message: "ERROR". If your Spring Boot services emit structured JSON with trace IDs (as in my Spring Boot structured logging guide), you can jump straight from an API error to every log line in that request.

Automate cleanup with Index Lifecycle Management (ILM)

Without automatic pruning, daily indices will eventually exhaust both shard limits and SSD space. Set up a 7-day deletion policy in Stack Management > Index Lifecycle Policies:

  1. Click Create policy and name it homelab-7day-retention.
  2. Leave Hot phase at its defaults.
  3. Keep Warm and Cold phases disabled (on a single-node homelab, tier migration adds nothing).
  4. Enable the Delete phase and set Move to delete phase after to 7 days.
  5. Save the policy and attach it to an index template matching homelab-docker-logs-*.

Elasticsearch will now drop indices older than 7 days automatically in the background.

Caveats and checklist

Keep these operational checks in mind when running ELK on a homelab:

  • Verify vm.max_map_count: On Linux hosts, confirm sysctl vm.max_map_count returns 262144 before troubleshooting Elasticsearch crashes.
  • Cap JVM heaps explicitly: Keep Elasticsearch at 1g and Logstash at 512m so log ingestion never OOM-kills your application containers.
  • Bind internal ports to 127.0.0.1: Only Kibana needs reverse-proxy access; keep Elasticsearch (9200) and Logstash (5044) off your public interfaces.
  • Bind ILM to an index template: Creating an ILM policy alone doesn’t delete anything until it’s attached to the homelab-docker-logs-* index template.

With Prometheus and Grafana handling time-series metrics and this ELK stack indexing container logs, both core pillars of homelab observability are in place.

This post is licensed under CC BY 4.0 by the author.