Docker driver client
Grafana Loki officially supports a Docker plugin that will read logs from Dockercontainers and ship them to Loki. The plugin can be configured to send the logsto a private Loki instance or Grafana Cloud.
Note
Docker plugins are not supported on Windows; see theDocker Engine managed plugin system documentation for more information.
Documentation on configuring the Loki Docker Driver can be found on theconfiguration page.If you have any questions or issues using the Docker plugin, open an issue intheLoki repository.
Install the Docker driver client
The Docker plugin must be installed on each Docker host that will be running containers you want to collect logs from.
Run the following command to install the plugin, updating the release version, or changing the architecture (arm64
andamd64
are currently supported), if needed:
docker plugin install grafana/loki-docker-driver:3.3.2-arm64 --alias loki --grant-all-permissions
Note
Add
-arm64
to the image tag for ARM64 hosts.
To check installed plugins, use thedocker plugin ls
command.Plugins that have started successfully are listed as enabled:
docker plugin ls
You should see output similar to the following:
ID NAME DESCRIPTION ENABLEDac720b8fcfdb loki Loki Logging Driver true
Once you have successfully installed the plugin you canconfigure it.
Upgrade the Docker driver client
The upgrade process involves disabling the existing plugin, upgrading (chaning version and architecture as needed), thenre-enabling and restarting Docker:
docker plugin disable loki --forcedocker plugin upgrade loki grafana/loki-docker-driver:3.3.2-arm64 --grant-all-permissionsdocker plugin enable lokisystemctl restart docker
Note
Update the version number to the appropriate version.
Uninstall the Docker driver client
To cleanly uninstall the plugin, disable and remove it:
docker plugin disable loki --forcedocker plugin rm loki
Known Issue: Deadlocked Docker Daemon
The driver keeps all logs in memory and will drop log entries if Loki is not reachable and if the quantity ofmax_retries
has been exceeded. To avoid the dropping of log entries, settingmax_retries
to zero allows unlimited retries; the driver will continue trying forever until Loki is again reachable. Trying forever may have undesired consequences, because the Docker daemon will wait for the Loki driver to process all logs of a container, until the container is removed. Thus, the Docker daemon might wait forever if the container is stuck.
The wait time can be lowered by settingloki-retries=2
,loki-max-backoff=800ms
,loki-timeout=1s
andkeep-file=true
. This way the daemon will be locked only for a short time and the logs will be persisted locally when the Loki client is unable to re-connect.
Also you can use non-blocking mode by settingservices.logger.logging.options.mode=non-blocking
in yourdocker-compose
file. Non-blocking means that the process of writing logs to Loki will not block the main flow of an application or service if Loki is temporarily unavailable or unable to process log messages. In non-blocking mode, log messages will be buffered and sent to Loki asynchronously, which allows the main thread to continue working without delay. If Loki is unavailable, log messages will be stored in a buffer and sent when Loki becomes available again. However, this setting is useful to prevent blocking the main flow of an application or service due to logging issues, but it can also lead to loss of log messages if the buffer overflows or if Loki is unavailable for a long time.
To avoid this issue, use the PromtailDocker target orDocker service discovery.
Is this page helpful?