loki docker log driver

27/04/2020

Send all docker logs to loki

https://github.com/grafana/loki/tree/master/cmd/docker-driver

install the docker plugin

docker plugin install grafana/loki-docker-driver:latest --alias loki --grant-all-permissions

activate the plugin globally

emacs /etc/docker/daemon.json
{
    "debug" : true,
    "log-driver": "loki",
    "log-opts": {
        "loki-url": "http://localhost:3100/loki/api/v1/push",
        "loki-batch-size": "400"
    }
}

reboot docker

service docker restart

run this to push one line by second to logs

docker run --name test -d busybox sh -c "while true; do $(echo date); sleep 1; done"

see docker's error log on ubuntu

journalctl -u docker.service

check that loki is getting something

curl -s "http://localhost:3100/api/prom/label"
curl -s "http://localhost:3100/api/prom/label/filename/values"
curl -G -s  "http://127.0.0.1:3100/loki/api/v1/query" --data-urlencode 'query={container_name="datelogger"}' | jq

Raccourcis