How to Deploy Elk Stack Using Docker Compose
To run Elasticsearch, Logstash, and Kibana (ELK) and the Elastic APM using Docker Compose, you will need to create a docker-compose.yml
file that defines the services and their configurations.
Here is an example docker-compose.yml
file that runs the ELK stack and the Elastic APM:
1version: '3'
2
3services:
4 elasticsearch:
5 image: docker.elastic.co/elasticsearch/elasticsearch:7.12.0
6 environment:
7 - discovery.type=single-node
8 ports:
9 - "9200:9200"
10 - "9300:9300"
11 volumes:
12 - ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
13 - esdata:/usr/share/elasticsearch/data
14 networks:
15 - elk-network
16
17 apm-server:
18 image: docker.elastic.co/apm/apm-server:7.12.0
19 environment:
20 - ELASTIC_APM_SERVER_URL=http://elasticsearch:9200
21 - ELASTIC_APM_SECRET_TOKEN=apm-secret-token
22 ports:
23 - "8200:8200"
24 networks:
25 - elk-network
26
27 logstash:
28 image: docker.elastic.co/logstash/logstash:7.12.0
29 environment:
30 - LS_JAVA_OPTS=-Xmx256m
31 - XPACK_MONITORING_ENABLED=true
32 volumes:
33 - ./logstash/config/logstash.yml:/usr/share/logstash/config/logstash.yml
34 - ./logstash/pipeline:/usr/share/logstash/pipeline
35 networks:
36 - elk-network
37 - apm-network
38 depends_on:
39 - elasticsearch
40
41 kibana:
42 image: docker.elastic.co/kibana/kibana:7.12.0
43 ports:
44 - "5601:5601"
45 networks:
46 - elk-network
47 depends_on:
48 - elasticsearch
49
50volumes:
51 esdata:
52
53networks:
54 elk-network:
55 driver: bridge
56 apm-network:
57 driver: bridge
This example uses the official Elasticsearch, Logstash, Kibana, and Elastic APM images from Elastic and it also creates two volumes and two networks.
To run this stack, you will need to have docker and docker-compose installed, then you can run the following command in the same directory as the docker-compose.yml
file:
1docker-compose up
2
This command will start all the services defined in the docker-compose.yml file, and you should be able to access Kibana at http://localhost:5601
.
It's important to note that the example uses specific version of the images, and you should check for the latest version before running the command.
Additionally, you can check the official documentation