The default Docker logging driver — json-file — writes container stdout/stderr to per-container JSON files under /var/lib/docker/containers/<id>/. Without rotation, those files grow until the disk fills. A chatty container can take down a host through nothing but log volume. This article covers the driver options, the rotation defaults that should be on every host, and the patterns for shipping logs off-box.
How to verify
Check the active logging driver and the actual log file state on a host:
docker info | grep -E "Logging Driver|log-opts"
docker inspect <container> --format '{{.HostConfig.LogConfig}}'
docker logs --tail 50 --timestamps <container>
# Where the json-file logs actually live and how big they are
du -sh /var/lib/docker/containers/*/*.log 2>/dev/null | sort -h | tail
ls -la /var/lib/docker/containers/$(docker inspect -f '{{.Id}}' <container>)/*.log
If the driver is json-file with no log-opts shown, log rotation is off — and you have a clock ticking until something fills the disk.
What’s happening
Docker captures container stdout and stderr at the daemon level and hands the stream to a configured logging driver. Every driver has the same input (a stream of log lines with metadata) and a different output:
json-file(default) — newline-delimited JSON files on the host.docker logsreads from these files. Rotation is off by default.local— likejson-filebut a Docker-native binary format with rotation enabled by default (max 100 MB / 5 files). Faster, smaller;docker logsstill works.journald— pipes into systemd’sjournald.journalctl CONTAINER_NAME=fooreads the logs. Rotation is whatever you set onjournald.syslog— sends to a local or remote syslog server. Format is configurable.fluentd— push to a Fluentd or Fluent Bit instance, then route from there.gelf— Graylog Extended Log Format, over UDP or TCP, for Graylog or compatible.awslogs— direct push to CloudWatch Logs. Useful on EC2 where AWS CLI auth is on the host.splunk,gcplogs, etc.
A driver other than json-file or local typically breaks docker logs — the daemon no longer holds the log buffer locally. That’s a real ergonomic loss; many teams use local + an external shipper (Promtail, Fluent Bit, Vector) reading the log files, keeping docker logs working while shipping off-box.
The procedure
- Set log rotation as a daemon default. Every host that runs containers needs this in
/etc/docker/daemon.json:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "5",
"compress": "true",
"tag": "{{.Name}}|{{.ImageName}}"
}
}
After saving, sudo systemctl restart docker. The rotation applies to containers started after the restart — existing containers keep their old config until recreated.
max-size: 10m rotates at 10 MB per file. max-file: 5 keeps 5 rotated files. Total per-container disk: ~50 MB. compress: true gzips rotated files. tag prepends a useful prefix to each line for downstream parsers.
- Per-container override. Useful for one chatty service that needs different limits:
docker run -d \
--log-driver json-file \
--log-opt max-size=50m \
--log-opt max-file=10 \
myapp:latest
In Compose:
services:
app:
logging:
driver: json-file
options:
max-size: "20m"
max-file: "5"
tag: "{{.Name}}"
- Switch to the
localdriver for better defaults and slightly better performance:
{
"log-driver": "local",
"log-opts": {
"max-size": "10m",
"max-file": "5",
"compress": "true"
}
}
local is a binary format under /var/lib/docker/containers/<id>/local-logs/. docker logs still works.
- Pipe to journald if the host already centralizes through systemd:
{
"log-driver": "journald",
"log-opts": {
"tag": "docker/{{.Name}}"
}
}
Then query via journalctl:
journalctl CONTAINER_NAME=myapp -n 100 -f
journalctl -u docker.service -t docker/myapp
Journald has its own rotation (SystemMaxUse, MaxRetentionSec in journald.conf). Set them explicitly or journald may swallow more disk than the json-file driver.
- Ship logs off-host. Three common patterns:
Promtail + Loki — Promtail reads the host’s docker log files, parses, ships to Loki. The Docker driver stays local or json-file. Promtail config:
scrape_configs:
- job_name: docker
static_configs:
- targets: [localhost]
labels:
job: docker
__path__: /var/lib/docker/containers/*/*-json.log
pipeline_stages:
- json:
expressions:
output: log
stream: stream
attrs:
- json:
expressions:
tag:
source: attrs
- regex:
expression: '^(?P<container_name>[^|]+)\|(?P<image>.+)$'
source: tag
- labels:
container_name:
stream:
- output:
source: output
Fluent Bit — lighter than Fluentd, supports all the same outputs. Run as a host daemon or as a privileged container with /var/lib/docker/containers:ro mounted.
CloudWatch on EC2 — the awslogs driver pushes directly:
{
"log-driver": "awslogs",
"log-opts": {
"awslogs-region": "us-east-1",
"awslogs-group": "/docker/myhost",
"awslogs-create-group": "true"
}
}
The EC2 instance must have an IAM role with logs:CreateLogStream, logs:PutLogEvents. docker logs no longer works — query CloudWatch instead.
- Structured logging from the application makes downstream parsing trivial. Have the app write JSON to stdout:
{"ts":"2026-06-02T10:15:23Z","level":"info","msg":"request","method":"GET","path":"/api/x","status":200,"latency_ms":47,"request_id":"abc123"}
Promtail/Fluent Bit can parse this directly into Loki/Elastic fields, making log queries answerable in seconds rather than minutes.
- Audit log volume per container so you catch chatty services before they fill the disk:
du -sh /var/lib/docker/containers/*/*.log* | sort -h | tail -10
A container generating >100 MB/hour of logs almost always has a tunable verbosity setting. Find it; don’t just bump the rotation higher.
Common pitfalls
- Leaving the daemon default (
json-file, no rotation) on production hosts. A single chatty container fills/var/lib/dockerand the daemon stops accepting writes. - Switching to
journaldwithout raising journald’sSystemMaxUse— journald defaults can be even more restrictive than your old json-file setup. - Using
awslogsorgelfand losingdocker logs. Engineers debugging on the host can’t tail anymore; provide the alternative (CloudWatch console, Graylog) in the runbook. - Shipping logs via the driver (
fluentd,gelf) without ensuring the receiver is highly available — if the receiver is down, the driver buffers, then blocks, then eventually crashes the container. - Logging secrets. Even with a driver that ships off-host, anything in stdout is captured. Audit application logs for tokens, passwords, cookie values.
We bake daemon-level log rotation and per-host log shipping into every client environment, and we audit log volume weekly as part of managed operations. For shipping pipelines, see Loki for log aggregation.