docker,

Configure Docker logging driver with Grafana Loki

Apr 06, 2022 · 1 min read · Post a comment
Configure Docker logging driver with Grafana Loki

Grafana Loki is a log aggregation tool inspired by Prometheus, or simply put Prometheus for logs. In this tutorial I’m gonna show you how to install and configure the Loki logging driver in Docker.

Prerequisites

  • Docker
  • Grafana Loki

Solution

Step 1. Install the loki docker plugin.

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

Step 2. Verify installation.

docker plugin ls

Example output:

ID             NAME          DESCRIPTION           ENABLED
1e87f2ea1a08   loki:latest   Loki Logging Driver   true

Step 3. Configure the Loki logging driver to be the default for all Docker containers. Open or create the /etc/docker/daemon.json file first.

Step 4. Add the following code block:

{
    "log-driver": "loki",
    "log-opts": {
        "loki-url": "https://<user_id>:<password>@<loki_endpoint>/loki/api/v1/push",
        "loki-batch-size": "400"
    }
}

Step 5. Restart the Docker service.

systemctl restart docker

Conclusion

Official Docker Driver Client from Grafana Loki documentation.
On a side note, follow our official channel on Telegram.