Docker Compose — Logging Drivers
Configure how Docker collects and stores container logs — from simple file-based logging to centralized log aggregation.
Default: json-file
Docker logs to JSON files by default. Configure rotation to prevent disk exhaustion:
services:
api:
image: myapi:latest
logging:
driver: json-file
options:
max-size: "10m" # Max 10 MB per log file
max-file: "5" # Keep 5 rotated files
compress: "true" # Compress rotated files
Without rotation, logs grow indefinitely and can fill your disk.
Available Drivers
| Driver | Destination | Use Case |
|---|---|---|
json-file |
Local files | Default, simple |
local |
Local files (optimized) | Better performance |
syslog |
Syslog daemon | Linux system logging |
journald |
systemd journal | Systemd-based hosts |
fluentd |
Fluentd collector | Centralized logging |
awslogs |
AWS CloudWatch | AWS deployments |
gcplogs |
Google Cloud Logging | GCP deployments |
none |
Nowhere | Disable logging |
Syslog Driver
services:
api:
image: myapi:latest
logging:
driver: syslog
options:
syslog-address: "udp://logserver:514"
tag: "myapp-api"
Fluentd Driver
services:
api:
image: myapi:latest
logging:
driver: fluentd
options:
fluentd-address: "localhost:24224"
tag: "docker.myapp.api"
Shared Logging Config
Use YAML extensions to share logging config:
x-logging: &default-logging
logging:
driver: json-file
options:
max-size: "10m"
max-file: "5"
services:
api:
<<: *default-logging
image: myapi:latest
worker:
<<: *default-logging
image: myworker:latest
db:
<<: *default-logging
image: postgres:16
Disable Logging
services:
noisy-service:
image: something:latest
logging:
driver: none
View Logs
# Docker Compose logs (works with json-file and local)
docker compose logs -f api
# Raw log file location
ls /var/lib/docker/containers/<container-id>/*-json.log
Summary
| Driver | Performance | Remote | docker compose logs |
|---|---|---|---|
| json-file | Good | No | Yes |
| local | Better | No | Yes |
| syslog | Good | Yes | No |
| fluentd | Good | Yes | No |
| none | N/A | No | No |
Quick Reference
| Item | Detail |
|---|---|
| json-file | Default driver, configure max-size/max-file |
| max-size | Max log file size (e.g. 10m) |
| max-file | Number of rotated files to keep |
| local | Optimized local driver |
| fluentd | Centralized log collection |
| none | Disable logging entirely |