Configuring the Docker Driver
The command can be configured to use a different logging driverthan the Docker daemon’s default with the --log-driver
flag. Any options thatthe logging driver supports can be set using the --log-opt <NAME>=<VALUE>
flag.--log-opt
can be passed multiple times for each option to be set.
The following command will start Grafana in a container and send logs to GrafanaCloud, using a batch size of 400 entries and no more than 5 retries if a sendfails.
Change the default logging driver
If you want the Loki logging driver to be the default for all containers,change Docker’s daemon.json
file (located in /etc/docker
on Linux) and setthe value of log-driver
to loki
:
{
"log-driver": "loki"
}
Options for the logging driver can also be configured with log-opts
in thedaemon.json
:
After changing daemon.json
, restart the Docker daemon for the changes to takeeffect. All containers from that host will then send logs to Loki.
You can also configure the logging driver for a directly in your compose file. This also applies for docker-compose
:
version: "3.7"
services:
logger:
image: grafana/grafana
logging:
options:
loki-url: "https://<user_id>:<password>@logs-us-west1.grafana.net/loki/api/v1/push"
You can then deploy your stack using:
Or with docker-compose
:
docker-compose -f docker-compose.yaml up
Once deployed, the Grafana service will send its logs to Loki.
Labels
By default, the Docker driver will add the following labels to each log line:
filename
: where the log is written to on diskhost
: the hostname where the log has been generatedcontainer_name
: the name of the container generating logsswarm_stack
,swarm_service
: added when deploying from Docker Swarm.
Custom labels can be added using the loki-external-labels
,loki-pipeline-stage-file
, labels
, env
, and env-regex
options. See thenext section for all supported options.
The following are all supported options that the Loki logging driver supports:
Troubleshooting
Plugin logs can be found as docker daemon log. To enable debug mode refer to theDocker daemon documentation.
The standard output (stdout
) of a plugin is redirected to Docker logs. Suchentries are prefixed with plugin=
.
Depending on your system, location of Docker daemon logging may vary. Refer tolog location for your specific platform.