Enable EFK Stack (7.x.x) on your Local using Docker Compose
2 min readMar 6, 2023
version: '2.2'
services:
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.9
container_name: es01
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es02,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data01:/usr/share/elasticsearch/data
ports:
- 9200:9200
healthcheck:
test: ["CMD-SHELL", "curl -s http://localhost:9200/_cluster/health | grep -vq '\"status\":\"red\"'"]
retries: 10
interval: 20s
networks:
- elastic
es02:
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.9
container_name: es02
environment:
- node.name=es02
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data02:/usr/share/elasticsearch/data
networks:
- elastic
es03:
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.9
container_name: es03
environment:
- node.name=es03
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es02
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data03:/usr/share/elasticsearch/data
networks:
- elastic
apm-server:
image: docker.elastic.co/apm/apm-server:7.17.9
ports:
- "8200:8200"
- "6060:6060"
command: >
apm-server -e
-E output.elasticsearch.hosts=["es01:9200"]
-E output.elasticsearch.protocol=http
cap_drop:
- ALL
cap_add:
- CHOWN
- DAC_OVERRIDE
- SETGID
- SETUID
logging:
driver: 'json-file'
options:
max-size: '2m'
max-file: '5'
depends_on:
- es01
healthcheck:
test: ["CMD", "curl", "--write-out", "'HTTP %{http_code}'", "--silent", "--output", "/dev/null", "http://apm-server:8200/healthcheck"]
retries: 10
interval: 10s
networks:
- elastic
kibana:
depends_on:
es01:
condition: service_healthy
image: docker.elastic.co/kibana/kibana:7.17.9
ports:
- 5601:5601
environment:
- SERVERNAME=kibana
- ELASTICSEARCH_HOSTS=http://es01:9200
- ELASTICSEARCH_USERNAME=kibana_system
- ELASTICSEARCH_PASSWORD=Jakarta123
mem_limit: 1073741824
healthcheck:
test:
[
"CMD-SHELL",
"curl -s -I http://localhost:5601 | grep -q 'HTTP/1.1 302 Found'",
]
interval: 10s
timeout: 10s
retries: 120
networks:
- elastic
fluentd:
depends_on:
es01:
condition: service_healthy
build:
context: ${WORKING_DIR_GOLANG}/apmefk-docker-compose/fluentd
dockerfile : Dockerfile
volumes:
- ${WORKING_DIR_GOLANG}/fluentd-docker-compose/conf:/fluentd/etc
- ${WORKING_DIR_PHP}/logstrial:/app/logs
ports:
- "24224:24224"
- "24224:24224/udp"
networks:
- elastic
volumes:
data01:
driver: local
data02:
driver: local
data03:
driver: local
networks:
elastic:
driver: bridge
I will explain more detail in different ocassion. But for now, I just want to answer the problem faced by engineer who want enable their own EFK environment in their local — solve their centralized logging problem. Happy logging. :)
Bonus : APM server included