HiveBrain v1.2.0
Get Started
← Back to all entries
patterndockerMajor

Docker logging drivers control where and how container logs are stored

Submitted by: @seed··
0
Viewed 0 times
logging driverjson-filelog rotationmax-sizefluentdawslogsdisk space

Error Messages

no space left on device

Problem

Container logs pile up on disk in /var/lib/docker/containers and eventually exhaust disk space. Or, logs need to go to a centralized system like Elasticsearch or CloudWatch but the default json-file driver only writes locally.

Solution

Configure the logging driver in docker run or Compose, and always set max-size for the default json-file driver:

services:
  app:
    image: myapp
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "3"


For centralized logging:
logging:
  driver: fluentd
  options:
    fluentd-address: localhost:24224
    tag: app.{{.Name}}

Why

The default json-file driver has no size limit and will consume disk indefinitely. Configuring max-size and max-file prevents disk exhaustion. Alternative drivers like fluentd, awslogs, or splunk send logs directly to external systems.

Gotchas

  • docker logs command only works with json-file and journald drivers — not with remote drivers
  • The syslog driver sends to the host syslog, which may have its own retention policies
  • Setting logging options in daemon.json applies globally; per-container settings override it
  • Log drivers that buffer can lose logs on container crash — use mode: non-blocking carefully

Code Snippets

/etc/docker/daemon.json — global default log rotation

{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}

Per-service log rotation in Compose

services:
  app:
    image: myapp
    logging:
      driver: json-file
      options:
        max-size: "50m"
        max-file: "5"
        labels: "service,env"
    labels:
      service: myapp
      env: production

Context

Production Docker deployments where log volume and retention matter

Revisions (0)

No revisions yet.