Elastic Stack on Docker
Preconfigured Security, Tools, and Self-Monitoring
Configured to be ready to be used for Log, Metrics, APM, Alerting, Machine Learning, and Security (SIEM) usecases.
Introduction
Elastic Stack (ELK) Docker Composition, preconfigured with Security, Monitoring, and Tools; Up with a Single Command.
Suitable for Demoing, MVPs and small production deployments.
Stack Version: 9.4.2 ๐ - Based on Official Elastic Docker Images
You can change Elastic Stack version by setting
ELK_VERSIONin.envfile and rebuild your images. Any version >= 9.0.0 is compatible with this template.โ ๏ธ Upgrading from 8.x? See the Upgrade Notes section below for breaking changes and migration steps.
Main Features ๐
- Configured as a Production Single Node Cluster. (With a multi-node cluster option for experimenting).
- Security Enabled By Default.
- Configured to Enable:
- Logging & Metrics Ingestion
- Option to collect logs of all Docker Containers running on the host. via
mise run collect-docker-logs.
- Option to collect logs of all Docker Containers running on the host. via
- APM
- Alerting
- Machine Learning
- Anomaly Detection
- SIEM (Security information and event management).
- Enabling Trial License
- Logging & Metrics Ingestion
- Use Docker Compose and
.envto configure your entire stack parameters. - Persist Elasticsearch's Keystore and SSL Certifications.
- Self-Monitoring Metrics Enabled (using Metricbeat for ES 9+).
- Prometheus Exporters for Stack Metrics.
- Embedded Container Healthchecks for Stack Images.
More points
And comparing Elastdocker and the popular deviantony/docker-elk
Expand...
One of the most popular ELK on Docker repositories is the awesome deviantony/docker-elk.
Elastdocker differs from deviantony/docker-elk in the following points.
Security enabled by default using Basic license, not Trial.
Persisting data by default in a volume.
Run in Production Mode (by enabling SSL on Transport Layer, and add initial master node settings).
Persisting Generated Keystore, and create an extendable script that makes it easier to recreate it every-time the container is created.
Parameterize credentials in .env instead of hardcoding
elastich:changemein every component config.Parameterize all other Config like Heap Size.
Add recommended environment configurations as Ulimits and Swap disable to Docker Compose.
Make it ready to be extended into a multinode cluster.
Configuring the Self-Monitoring and the Filebeat agent that ship ELK logs to ELK itself. (as a step to shipping it to a monitoring cluster in the future).
Configured Prometheus Exporters.
The Makefile that simplifies everything into some simple commands.
Automatic Docker Container Log Collection
Collect logs from all Docker containers on your host with a single command:
mise run collect-docker-logs
Filebeat automatically discovers containers, parses logs, and ships them to Elasticsearch. View and analyze everything in Kibana with zero configuration.
Requirements
- Docker 20.05 or higher with Docker Compose v2
- 4GB RAM (For Windows and MacOS make sure Docker's VM has more than 4GB+ memory.)
Setup
Clone the Repository
git clone https://github.com/sherifabdlnaby/elastdocker.gitInitialize Elasticsearch Keystore and TLS Self-Signed Certificates
mise run stack:setupFor Linux's docker hosts only. By default virtual memory is not enough so run the next command as root
sysctl -w vm.max_map_count=262144Start Elastic Stack
mise run up # docker compose up -dVisit Kibana at https://localhost:5601 or
https://:5601Default Username:
elastic, Password:changeme- Notice that Kibana is configured to use HTTPS, so you'll need to write
https://beforelocalhost:5601in the browser. - Modify
.envfile for your needs, most importantlyELASTIC_PASSWORDthat setup your superuserelastic's password,ELASTICSEARCH_HEAP&LOGSTASH_HEAPfor Elasticsearch & Logstash Heap Size.
- Notice that Kibana is configured to use HTTPS, so you'll need to write
Whatever your Host (e.g AWS EC2, Azure, DigitalOcean, or on-premise server), once you expose your host to the network, ELK component will be accessible on their respective ports. Since the enabled TLS uses a self-signed certificate, it is recommended to SSL-Terminate public traffic using your signed certificates.
๐๐ปโโ๏ธ To start ingesting logs, you can start by running
mise run collect-docker-logswhich will collect your host's container logs.
Additional Commands
Expand
To Start Monitoring and Prometheus Exporters
mise run monitoring
To Ship Docker Container Logs to ELK
mise run collect-docker-logs
To Start Elastic Stack, Tools and Monitoring
mise run all
To Start 2 Extra Elasticsearch nodes (recommended for experimenting only)
mise run nodes
To Rebuild Images
mise run build
Bring down the stack
mise run down
Reset everything, Remove all containers, and delete DATA
mise run prune
Configuration
- Some Configuration are parameterized in the
.envfile.ELASTIC_PASSWORD, userelastic's password (default:changemepls).ELK_VERSIONElastic Stack Version (default:9.4.2)ELASTICSEARCH_HEAP, how much Elasticsearch allocate from memory (default: 1GB -good for development only-)LOGSTASH_HEAP, how much Logstash allocate from memory.- Other configurations which their such as cluster name, and node name, etc.
- Elasticsearch Configuration in
elasticsearch.ymlat./elasticsearch/config. - Logstash Configuration in
logstash.ymlat./logstash/config/logstash.yml. - Logstash Pipeline in
main.confat./logstash/pipeline/main.conf. - Kibana Configuration in
kibana.ymlat./kibana/config. - Metricbeat Configuration in
metricbeat.ymlat./metricbeat/config(for Stack Monitoring in ES 9+).
Setting Up Keystore
You can extend the Keystore generation script by adding keys to ./setup/keystore.sh script. (e.g Add S3 Snapshot Repository Credentials)
To Re-generate Keystore:
mise run keystore
Notes
โ ๏ธ Elasticsearch HTTP layer is using SSL, thus mean you need to configure your elasticsearch clients with the
CAinsecrets/certs/ca/ca.crt, or configure client to ignore SSL Certificate Verification (e.g--insecureincurl).Adding Two Extra Nodes to the cluster will make the cluster depending on them and won't start without them again.
The stack is driven by mise tasks; run
mise tasksto list them. TheMakefilekeeps the same commands but is deprecated.Elasticsearch will save its data to a volume named
elasticsearch-dataElasticsearch Keystore (that contains passwords and credentials) and SSL Certificate are generated in the
./secretsdirectory by the setup command.Make sure to run
mise run stack:setupif you changedELASTIC_PASSWORDand to re