Try using Grot AI Grot AI for this query ->
Promo banner icon

What’s new: Grafana 13 release, the latest in AI, OSS project updates, and more from GrafanaCON2026

Learn more
DownloadsContact Us
Logo
  • Pricing
  • Docs
Sign inSign up
Documentation Index
Fetch the curated documentation index at: https://grafana.com/llms.txt

Fetch the complete documentation index at: https://grafana.com/llms-full.txt
Use this file to discover all available pages before exploring further.

STOP! If you are an AI agent or LLM, read this before continuing. This is the HTML version of a Grafana documentation page. Always request the Markdown version instead - HTML wastes context. Get this page as Markdown: https://grafana.com/docs/loki/latest/send-data/docker-driver/configuration.md (append .md) or send Accept: text/markdown to https://grafana.com/docs/loki/latest/send-data/docker-driver/configuration/. For the curated documentation index, use https://grafana.com/llms.txt. For the complete documentation index, use https://grafana.com/llms-full.txt.

Menu
Documentationbreadcrumb arrow Grafana Lokibreadcrumb arrow Send databreadcrumb arrow Docker driverbreadcrumb arrow Configure Docker driver
Open source

Docker driver client configuration

You can use Grafana Cloud to avoid installing, maintaining, and scaling your own instance of Grafana Loki. Create a free account to get started, which includes free forever access to 10k metrics, 50GB logs, 50GB traces, 500VUh k6 testing & more.

The Docker daemon on each machine has a default logging driver and each container will use the default driver unless configured otherwise.

Installation

Before configuring the plugin, install or upgrade the Grafana Loki Docker Driver Client

Change the logging driver for a container

The docker run command can be configured to use a different logging driver than the Docker daemon’s default with the --log-driver flag. Any options that the 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 Grafana Cloud, using a batch size of 400 entries and no more than 5 retries if a send fails.

Bash
docker run --log-driver=loki \
    --log-opt loki-url="https://<user_id>:<password>@logs-us-west1.grafana.net/loki/api/v1/push" \
    --log-opt loki-retries=5 \
    --log-opt loki-batch-size=400 \
    grafana/grafana

Note

The Loki logging driver still uses the json-log driver in combination with sending logs to Loki, this is mainly useful to keep the docker logs command working. You can adjust file size and rotation using the respective log option max-size and max-file. Keep in mind that default values for these options are not taken from json-log configuration. You can disable JSON log file creation by setting the log option no-file to true, but this also disables docker logs for the container.

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 set the value of log-driver to loki:

JSON
{
  "debug": true,
  "log-driver": "loki"
}

Options for the logging driver can also be configured with log-opts in the daemon.json:

JSON
{
  "debug": true,
  "log-driver": "loki",
  "log-opts": {
    "loki-url": "https://<user_id>:<password>@logs-us-west1.grafana.net/loki/api/v1/push",
    "loki-batch-size": "400"
  }
}

Note

log-opt configuration options in daemon.json must be provided as

strings. Boolean and numeric values (such as the value for loki-batch-size in the example above) must therefore be enclosed in quotes (").

After changing daemon.json, restart the Docker daemon for the changes to take effect. All newly created containers from that host will then send logs to Loki via the driver.

Configure the logging driver for a Swarm service or Compose

You can also configure the logging driver for a swarm service directly in your compose file. This also applies for docker-compose:

YAML
version: "3.7"
services:
  logger:
    image: grafana/grafana
    logging:
      driver: loki
      options:
        loki-url: "https://<user_id>:<password>@logs-prod-us-central1.grafana.net/loki/api/v1/push"

You can then deploy your stack using:

Bash
docker stack deploy my_stack_name --compose-file docker-compose.yaml

Or with docker-compose:

Bash
docker-compose -f docker-compose.yaml up

Once deployed, the Grafana service will send its logs to Loki.

Note

Stack name and service name for each swarm service and project name and service name for each compose service are automatically discovered and sent as Loki labels, this way you can filter by them in Grafana.

Labels

Loki can receive a set of labels along with log line. These labels are used to index log entries and query back logs using LogQL stream selector.

By default, the Docker driver will add the following labels to each log line:

  • filename: where the log is written to on disk
  • host: the hostname where the log has been generated
  • swarm_stack, swarm_service: added when deploying from Docker Swarm.
  • compose_project, compose_service: added when deploying with Docker Compose.

Custom labels can be added using the loki-external-labels, loki-pipeline-stages, loki-pipeline-stage-file, labels, env, and env-regex options. See the next section for all supported options.

loki-external-labels have the default value of container_name={{.Name}}. If you have custom value for loki-external-labels then that will replace the default value, meaning you won’t have container_name label unless you explicitly add it (e.g: loki-external-labels: "job=docker,container_name={{.Name}}".

Pipeline stages

While you can provide loki-pipeline-stage-file it can be hard to mount the configuration file to the driver root filesystem. This is why another option loki-pipeline-stages is available allowing you to pass a list of stages inlined. Pipeline stages are run at last on every lines.

The example docker-compose below configures 2 stages, one to extract level values and one to set it as a label:

YAML
version: "3"
services:
  grafana:
    image: grafana/grafana
    logging:
      driver: loki
      options:
        loki-url: http://host.docker.internal:3100/loki/api/v1/push
        loki-pipeline-stages: |
          - regex:
              expression: '(level|lvl|severity)=(?P<level>\w+)'
          - labels:
              level:
    ports:
      - "3000:3000"

Note

Note the loki-pipeline-stages: | letting you keep the indentation correct.

When using docker run you can also pass the value via a string parameter like such:

Bash
read -d '' stages << EOF
- regex:
     expression: '(level|lvl|severity)=(?P<level>\\\w+)'
- labels:
    level:
EOF

docker run --log-driver=loki \
    --log-opt loki-url="http://host.docker.internal:3100/loki/api/v1/push" \
    --log-opt loki-pipeline-stages="$stages" \
    -p 3000:3000 grafana/grafana

This is a bit more difficult as you need to properly escape bash special characters. (note \\\w+ for \w+)

Providing both loki-pipeline-stage-file and loki-pipeline-stages will cause an error.

Relabeling

You can use Prometheus relabeling configuration to modify labels discovered by the driver. The configuration must be passed as a YAML string like the pipeline stages.

Relabeling phase will happen only once per container and it is applied on the container metadata when it starts. So you can for example rename the labels that are only available during the starting of the container, not the labels available on log lines. Use pipeline stages instead.

For example the configuration below will rename the label swarm_stack and swarm_service to respectively namespace and service.

YAML
version: "3"
services:
  grafana:
    image: grafana/grafana
    logging:
      driver: loki
      options:
        loki-url: http://host.docker.internal:3100/loki/api/v1/push
        loki-relabel-config: |
          - action: labelmap
            regex: swarm_stack
            replacement: namespace
          - action: labelmap
            regex: swarm_(service)
    ports:
      - "3000:3000"

Supported log-opt options

To specify additional logging driver options, you can use the –log-opt NAME=VALUE flag.

OptionRequired?Default ValueDescription
loki-urlYesLoki HTTP push endpoint.
loki-external-labelsNocontainer_name={{.Name}}Additional label value pair separated by , to send with logs. The value is expanded with the Docker tag template format. (eg: container_name={{.ID}}.{{.Name}},cluster=prod)
loki-timeoutNo10sThe timeout to use when sending logs to the Loki instance. Valid time units are “ns”, “us” (or “µs”), “ms”, “s”, “m”, “h”.
loki-batch-waitNo1sThe amount of time to wait before sending a log batch complete or not. Valid time units are “ns”, “us” (or “µs”), “ms”, “s”, “m”, “h”.
loki-batch-sizeNo1048576The maximum size of a log batch to send.
loki-min-backoffNo500msThe minimum amount of time to wait before retrying a batch. Valid time units are “ns”, “us” (or “µs”), “ms”, “s”, “m”, “h”.
loki-max-backoffNo5mThe maximum amount of time to wait before retrying a batch. Valid time units are “ns”, “us” (or “µs”), “ms”, “s”, “m”, “h”.
loki-retriesNo10The maximum amount of retries for a log batch. Setting it to 0 will retry indefinitely.
loki-pipeline-stage-fileNoThe location of a pipeline stage configuration file (example). Pipeline stages allows to parse log lines to extract more labels, see associated documentation.
loki-pipeline-stagesNoThe pipeline stage configuration provided as a string see pipeline stages and associated documentation.
loki-relabel-configNoA Prometheus relabeling configuration allowing you to rename labels see relabeling.
loki-tenant-idNoSet the tenant id (http headerX-Scope-OrgID) when sending logs to Loki. It can be overridden by a pipeline stage.
loki-tls-ca-fileNoSet the path to a custom certificate authority.
loki-tls-cert-fileNoSet the path to a client certificate file.
loki-tls-key-fileNoSet the path to a client key.
loki-tls-server-nameNoName used to validate the server certificate.
loki-tls-insecure-skip-verifyNofalse*Allow to skip tls verification.
loki-proxy-urlNoProxy URL use to connect to Loki.
no-fileNofalse*When false (default), the driver creates a local JSON log file for each container, which enables docker logs. Set to true to skip creating JSON log files entirely — no disk space is used for logs, but docker logs will not work for the container.
keep-fileNofalse*When false (default), the JSON log file for a container is deleted when the container stops. Set to true to retain the JSON log file after the container stops. Has no effect when no-file=true, because no JSON log file is created.
max-sizeNo-1The maximum size of the log before it is rolled. A positive integer plus a modifier representing the unit of measure (k, m, or g). Defaults to -1 (unlimited). This is used by json-log required to keep the docker log command working.
max-fileNo1The maximum number of log files that can be present. If rolling the logs creates excess files, the oldest file is removed. Only effective when max-size is also set. A positive integer. Defaults to 1.
labelsNoComma-separated list of keys of labels, which should be included in message, if these labels are specified for container.
envNoComma-separated list of keys of environment variables to be included in message if they specified for a container.
env-regexNoA regular expression to match logging-related environment variables. Used for advanced log label options. If there is collision between the label and env keys, the value of the env takes precedence. Both options add additional fields to the labels of a logging message.

no-file and keep-file interactions

The no-file and keep-file options control whether JSON log files are created and how long they are kept:

no-filekeep-fileJSON log file created?Deleted on container stop?docker logs available?
falsefalseYesYesYes
falsetrueYesNoYes
true(any)NoN/ANo

*note:

Boolean values in the configuration file only accept the following string type:

ValueAccepted Values
true"1", "t", "T", "true", "TRUE", "True"
false"0", "f", "F", "false", "FALSE", "False"

Troubleshooting

Plugin logs can be found as docker daemon log. To enable debug mode refer to the Docker daemon documentation.

The standard output (stdout) of a plugin is redirected to Docker logs. Such entries are prefixed with plugin=.

To find out the plugin ID of the Loki logging driver, use docker plugin ls and look for the loki entry.

Depending on your system, location of Docker daemon logging may vary. Refer to Docker documentation for Docker daemon log location for your specific platform.

Was this page helpful?

Suggest an edit in GitHub
Create a GitHub issue
Email docs@grafana.com
Help and support
Community

Related resources from Grafana Labs

Additional helpful documentation, links, and articles:
webinar icon
Video
Getting started with logging and Grafana Loki
Getting started with logging and Grafana Loki
See a demo of the updated features in Loki, and how to create metrics from logs and alert on your logs with powerful Prometheus-style alerting rules.
video icon
Video
Essential Grafana Loki configuration settings
Essential Grafana Loki configuration settings
This webinar focuses on Grafana Loki configuration including agents Promtail and Docker; the Loki server; and Loki storage for popular backends.
video icon
Video
Scaling and securing your logs with Grafana Loki
Scaling and securing your logs with Grafana Loki
This webinar covers the challenges of scaling and securing logs, and how Grafana Cloud Logs powered by Grafana Loki can help, cost-effectively.
Technical documentation Plugin catalog
Choose a product
Viewing: v3.7.x (latest) Find another version
  • Grafana Loki
  • Release notes
    • Release cadence
    • v3.7
    • v3.6
    • v3.5
    • v3.4
    • v3.3
    • v3.2
    • v3.1
    • v3.0
    • V2.9
    • V2.8
    • V2.7
    • V2.6
    • V2.5
    • V2.4
    • V2.3
  • Get started
    • Loki overview
    • Quick Start
      • Loki quickstart
      • Loki Tutorial
    • Architecture
    • Components
    • Deployment modes
    • Labels
      • Label best practices
      • Cardinality
      • Structured metadata
      • Modify default labels
    • Hash rings
  • Set up
    • Size the cluster
    • Install
      • Install using Helm
        • Helm chart components
        • Install monolithic Loki
        • Install microservice Loki
        • Install scalable Loki
        • Cloud Deployment Guides
          • Deploy on AWS
          • Deploy on Azure
          • Deploy on GCP
        • Configure storage
        • Helm chart values
        • Monitoring
      • Install using Tanka
      • Install using Docker
      • Install locally
      • Install on Istio
      • Install from source
    • Migrate
      • Migrate to Alloy
      • Migrate from SSD to distributed
      • Migrate to TSDB
      • Migrate from `loki-distributed`
      • Migrate to three targets
      • Migrate to Thanos storage clients
    • Upgrade
      • Upgrade the Helm chart to 3.0
      • Upgrade the Helm chart to 6.0
      • Upgrade to Community Helm chart
  • Configure
    • Best practices
    • Storage
    • Usage statistics
    • Examples
      • Configuration
      • Thanos storage examples
      • Query frontend example
  • Send data
    • Grafana Alloy
      • Sending Logs to Loki via Kafka using Alloy
      • Sending OpenTelemetry logs to Loki using Alloy
    • OpenTelemetry
      • Native OTLP endpoint vs Loki Exporter
      • OTel Collector tutorial
    • Kubernetes Monitoring Helm
    • Promtail
    • Docker driver
      • Configure Docker driver
    • Fluent Bit
      • Fluent Bit tutorial
      • Fluent Bit Community Plugin
      • Fluent Bit
    • Fluentd
    • Lambda Promtail
    • Logstash plugin
    • k6 load testing
      • Log generation
      • Write path testing
      • Query testing
  • Query
    • Query best practices
    • LogQL simulator
    • Log queries
    • Metric queries
    • Template functions
    • LogCLI
      • Getting started
      • LogCLI tutorial
    • Matching IP addresses
    • Query examples
    • Query acceleration
    • Query Reference
    • Troubleshoot queries
  • Visualize
  • Alert
  • Manage
    • Loki Canary
    • Block unwanted queries
    • Caching
    • Rate limits
    • Query fairness
    • Shuffle sharding
    • Monitor Loki
      • Deploy Loki Meta Monitoring
      • Install Mixins
      • Single Binary Meta Monitoring
      • Key Metrics
    • Troubleshooting
      • Troubleshoot operations
      • Troubleshoot ingestion
      • Troubleshoot drilldown
      • Troubleshoot queries
    • Authentication
    • Bloom filters
    • Automatic stream sharding
    • Scale Loki
    • Recording rules
    • Storage
      • TSDB
      • BoltDB Shipper
      • Filesystem object store
      • Storage schema
      • Write Ahead Log
      • Log retention
      • Log entry deletion
      • Horizontal scaling of Compactor
      • Legacy storage
      • Table manager
    • Multi-tenancy
    • Autoscaling queriers
    • Upgrade
    • Overrides Exporter
    • Zone aware ingesters
  • Reference
    • Loki configuration reference
    • Loki HTTP API
    • Python examples
  • Community
    • Contacting the Loki Team
    • Contributing to Loki
    • Governance
    • Maintaining
      • Releasing Grafana Loki
        • Backport commits
        • Create Release Branch
        • Document metrics and configurations changes
        • Merge Release PR
        • Patch Go version
        • Patch vulnerabilities
        • Prepare Major Release
        • Prepare Release
        • Prepare Upgrade guide
        • Update version numbers
        • Version
      • Releasing Loki Build Image
    • Loki Improvement Documents (LIDs)
      • 0001: Introducing LIDs
      • 0002: Remote Rule Evaluation
      • 0003: Query fairness across users within tenants
      • 0004: Index Gateway Sharding
      • 0005: Loki mixin configuration improvements
      • 0006: Expose Split Logic in API
    • Design documents
      • Labels
      • Promtail Push API
      • Write-Ahead Logs
      • Ordering Constraint Removal
  • Copyright notice
Scroll for more
Read this in Grafana Cloud

Is this page helpful?

On this page
  • Installation
  • Change the logging driver for a container
  • Change the default logging driver
  • Configure the logging driver for a Swarm service or Compose
  • Labels
  • Pipeline stages
  • Relabeling
  • Supported log-opt options
  • no-file and keep-file interactions
  • *note:
  • Troubleshooting
Scroll for more

Still have questions?

Ask your questions. Let AI do the heavy lifting.

Ask AI icon
Newsletter icon

Get every update

Subscribe to our newsletter

By submitting, you agree to our Privacy policy

Grafana Cloud

  • Overview
  • Pricing
  • What's in the free tier?
  • AI Assistant
  • Application Observability
  • Kubernetes Monitoring
  • Dashboards & Visualization
  • Database Observability
  • Frontend Observability
  • Synthetic Monitoring
  • Performance & Load Testing
  • Incident Response & Management
  • What’s New
  • Grafana Cloud Status

Solutions

  • AI Observability
  • Full-Stack Observability
  • Infrastructure & Cloud Observability
  • Digital Experience Monitoring
  • Scaled Prometheus
  • Cost Management & Optimization
  • Site Reliability
  • Log Management
  • Migrate to OpenTelemetry

Integrations

  • All Integrations
  • All Plugins
  • AWS
  • Google Cloud
  • Microsoft Azure
  • Kubernetes
  • Datadog
  • New Relic

Open Source

  • Our Projects
  • GitHub
  • Downloads
  • Dashboard Templates

Learn

  • Documentation
  • Blog
  • Community
  • Events
  • Observability Survey & Reports

Company

  • About Grafana Labs
  • Careers
  • Partnerships
  • Newsroom
  • Success Stories
  • Contact Us
  • Getting Help
  • Professional Services
  • Hey AI

Compare

  • Datadog vs. Grafana Cloud
  • Dynatrace vs. Grafana Cloud
  • Elasticsearch vs. Grafana Cloud
  • New Relic vs. Grafana Cloud
  • PagerDuty vs. Grafana Cloud
  • Splunk vs. Grafana Cloud
Grafana Labs x unique logomark

Donut take our word for it. Try Grafana Cloud today.

Grafana Cloud StatusLegal & SecurityTerms of ServicePrivacy PolicyTrademark Policy

Copyright 2026 © Grafana Labs

FacebookXLinkedinGithubYoutubeReddit
Grafana Labs uses cookies for the normal operation of this website. Learn more.