Logging Drivers & Log Rotation in Docker Compose
Configure logging drivers and rotation so compose stacks do not fill disks.
In plain words
Choose a driver based on retrieval, backpressure and disk guarantees, then make every service use structured bounded output.
Think of it like…
Logging driver is the postal route: local boxes keep copies, a courier may stop delivery when the sorting center is offline, and rotation decides box size.
Where you’ve seen it
In practice, logging: { driver: local, options: { max-size: 10m, max-file: "5", compress: "true" } } is the concrete move for this job: configure logging drivers and rotation so compose stacks do not fill disks. The release is not accepted until write a controlled high-volume line, inspect Docker’s rotated file set and confirm the logging driver field in docker inspect confirms the result.
Words you’ll hear
- logging
- The implementation control in
logging: { driver: local, options: { max-size: 10m, max-file: "5", compress: "true" } }for configure logging drivers and rotation so compose stacks do not fill disks. - max-size
- The result to observe with
write a controlled high-volume line, inspect Docker’s rotated file set and confirm the logging driver field in docker inspect, rather than infer from a successful command alone. - Rotation
- The production boundary exposed when choosing fluentd because it is in production and then expecting docker compose logs to display the remote-only stream.
Visual diagram
Theory & deep dive
logging control path
The concrete mechanism is logging: { driver: local, options: { max-size: 10m, max-file: "5", compress: "true" } }. The observable result is write a controlled high-volume line, inspect Docker’s rotated file set and confirm the logging driver field in docker inspect; if those disagree, inspect the runtime evidence before changing unrelated settings.
Configure logging drivers and rotation so compose stacks do not fill disks. Keep logging, max-size and Rotation in the same deployment record so the intent and the observed state cannot drift apart.
logging: { driver: local, options: { max-size: 10m, max-file: "5", compress: "true" } }
write a controlled high-volume line, inspect Docker’s rotated file set and confirm the logging driver field in docker inspect, not with command success alone.Rotation failure boundary
A centralized driver can block or lose local logs depending on mode and collector availability. Rotation only limits each container, so the aggregate number of replicas times file count still determines worst-case disk consumption. The narrow failure to design for is choosing fluentd because it is in production and then expecting docker compose logs to display the remote-only stream.
Accept this compromise explicitly: Local bounded logs provide incident access; remote drivers centralize and correlate but add collector availability and delivery semantics. The controlled check-write a controlled high-volume line, inspect Docker’s rotated file set and confirm the logging driver field in docker inspect-also identifies the point where a different design is safer.
Exercise this failure safely: choosing fluentd because it is in production and then expecting docker compose logs to display the remote-only stream.
How it works, step by step
Step 1 of 41. State the boundary
Write down why the workload needs this: A centralized driver can block or lose local logs depending on mode and collector availability. Rotation only limits each container, so the aggregate number of replicas times file count still determines worst-case disk consumption.
- Intent
- logging
When to use it & trade-offs
What it is
Compose logging maps to Docker logging driver options. json-file/local retain logs for docker compose logs on the host, while syslog, fluentd or awslogs send logs elsewhere and can make the CLI log buffer unavailable. max-size and max-file cap local rotation per container.
Why it matters: A centralized driver can block or lose local logs depending on mode and collector availability. Rotation only limits each container, so the aggregate number of replicas times file count still determines worst-case disk consumption.
When to reach for it
- The fit is strongest for this job: configure logging drivers and rotation so compose stacks do not fill disks. Pair it with
write a controlled high-volume line, inspect Docker’s rotated file set and confirm the logging driver field in docker inspectin the runbook. - Production logging changes should make max-size observable through
logging: { driver: local, options: { max-size: 10m, max-file: "5", compress: "true" } }, rather than trusting the runtime default. - Keep a rollback example for the case where choosing fluentd because it is in production and then expecting docker compose logs to display the remote-only stream.
When to avoid or be careful
- Do not accept command success while the system can still fail by choosing fluentd because it is in production and then expecting docker compose logs to display the remote-only stream.
- Avoid erasing Rotation protection merely to dodge this cost: “Local bounded logs provide incident access; remote drivers centralize and correlate but add collector availability and delivery semantics”.
- Do not replace the evidence path-
write a controlled high-volume line, inspect Docker’s rotated file set and confirm the logging driver field in docker inspect-with a screenshot or a mutable tag.
logging: { driver: local, options: { max-size: 10m, max-file: "5", compress: "true" } }: practical choices
Strengths: Compose logging maps to Docker logging driver options. json-file/local retain logs for docker compose logs on the host, while syslog, fluentd or awslogs send logs elsewhere and can make the CLI log buffer unavailable. max-size and max-file cap local rotation per container.
Watch out: Local bounded logs provide incident access; remote drivers centralize and correlate but add collector availability and delivery semantics.
Strengths: It can begin with logging: { driver: local, options: { max-size: 10m, max-file: "5", compress: "true" } } and fewer surrounding controls.
Watch out: It silently accepts choosing fluentd because it is in production and then expecting docker compose logs to display the remote-only stream, which makes the result hard to reproduce after promotion.
Strengths: A centralized driver can block or lose local logs depending on mode and collector availability. Rotation only limits each container, so the aggregate number of replicas times file count still determines worst-case disk consumption.
Watch out: The platform adds an ownership and debugging layer; retain write a controlled high-volume line, inspect Docker’s rotated file set and confirm the logging driver field in docker inspect as the direct check.
Interview signals & numbers to know
When this topic comes up
- logging: { driver: local, options: { max-size: 10m, max-file: "5", compress: "true" } }
- write a controlled high-volume line, inspect Docker’s rotated file set and confirm the logging driver field in docker inspect
- Failure signature: choosing fluentd because it is in production and then expecting docker compose logs to display the remote-only stream
- Trade-off: Local bounded logs provide incident access; remote drivers centralize and correlate but add collector availability and delivery semantics.
Benchmarks & rules of thumb
- 10 MB
- size per rotated file in the example
- 5 files
- rotation history per container
- 50 MB
- nominal upper bound per container before shared metadata
Common mistakes & follow-ups
Common interview mistakes
- Treating a successful
logging: { driver: local, options: { max-size: 10m, max-file: "5", compress: "true" } }as proof and skippingwrite a controlled high-volume line, inspect Docker’s rotated file set and confirm the logging driver field in docker inspect. - Choosing fluentd because it is in production and then expecting docker compose logs to display the remote-only stream
- Optimizing logging without accepting that local bounded logs provide incident access; remote drivers centralize and correlate but add collector availability and delivery semantics.
Likely interviewer follow-ups
- Why does
logging: { driver: local, options: { max-size: 10m, max-file: "5", compress: "true" } }address logging here rather than through application code? - How would you distinguish healthy max-size from the failure “choosing fluentd because it is in production and then expecting docker compose logs to display the remote-only stream” using
write a controlled high-volume line, inspect Docker’s rotated file set and confirm the logging driver field in docker inspect? - When would this trade-off-“Local bounded logs provide incident access; remote drivers centralize and correlate but add collector availability and delivery semantics”-justify a different Rotation design?
logging: { driver: local, options: { max-size: 10m, max-file: "5", compress: "true" } }-and one proof-write a controlled high-volume line, inspect Docker’s rotated file set and confirm the logging driver field in docker inspect. Then name the boundary: choosing fluentd because it is in production and then expecting docker compose logs to display the remote-only stream.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Logging Drivers & Log Rotation in Docker Compose with generative AI interview Q&A and hands-on practice.