Setup the Elasticsearch Log Driver on Docker Swarm
Today we will look at a Elasticsearch logging driver for Docker.
Why a Log Driver?
By default the log output can be retrieved when using the docker service logs -f service_name, where log output of that service is shown via stdout. When having a lot of services in your swarm, it becomes useful logging all of your log output to a database service.
This is not just for Swarm but Docker stand alone as well.
In this tutorial we will use the Elasticsearch Log Driver, to log our logs for all our docker swarm services to Elasticsearch.
Installing to Elasticsearch Log Driver:
If you are running Docker Swarm, run this on all the nodes:
Have a look at your Elasticsearch indexes, and you will find the index which was specified in the log-options:
123
$ curl http://192.168.0.235:9200/_cat/indices?v
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open docker-2018.05.01 8FTqWq6nQlSGpYjD9M5qSg 5110 8.9kb 8.9kb
Lets have a look at the Elasticsearch Document which holds the data of the log entry:
Give it some time to launch and have a look at your indexes, and you will find the index which it wrote to:
1234
$ curl http://192.168.0.235:9200/_cat/indices?v
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open docker-2018.05.01 8FTqWq6nQlSGpYjD9M5qSg 5110 8.9kb 8.9kb
yellow open docker-whoami-2018.05.01 YebUtKa1RnCy86iP5_ylgg 51110 54.4kb 54.4kb