Interview's MateDocker
Interview's Mate

Docker

Compose · Networking · Security · Ops

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Docker topics
Lesson 96/ 160
05. Docker Compose & Multi-Container Apps

Logging Drivers & Log Rotation in Docker Compose

Configure logging drivers and rotation so compose stacks do not fill disks.

Intermediatelogging · max-size3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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

Loading interactive 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.

Concrete logging setup

logging: { driver: local, options: { max-size: 10m, max-file: "5", compress: "true" } }

Key takeaway: Prove max-size with 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.

Deliberate failure test

Exercise this failure safely: choosing fluentd because it is in production and then expecting docker compose logs to display the remote-only stream.

Key takeaway: Local bounded logs provide incident access; remote drivers centralize and correlate but add collector availability and delivery semantics.

How it works, step by step

Step 1 of 4
Design

1. 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.

Choose a driver based on retrieval, backpressure and disk guarantees, then make every service use structured bounded output.
Key numbers at this step
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 inspect in 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

Explicit logging
Best for: Configure logging drivers and rotation so compose stacks do not fill disks, with a reviewed runbook.

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.

Ambient default
Best for: Short-lived max-size experiments with low blast radius.

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.

Managed Rotation
Best for: Teams that centralize Rotation policy across many workloads.

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 skipping write 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?
Interview tip: Give one concrete operation-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

Loading quiz

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.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Resource Limits & Reservations in Compose (CPU & Memory)
Next topic
Building Full-Stack Stacks (React + FastAPI/Node + Postgres + Redis)