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 130/ 160
07. CI/CD, Registries & Production Operations

Preventing Disk Exhaustion via Log Rotation (max-size, max-file)

Configure max-size and max-file so container logs cannot fill the disk.

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

In plain words

Set bounded log policy in daemon or Compose defaults and alert on host free bytes, inodes and logging errors.

Think of it like…

Rotation is a moving window of security-camera footage: a five-minute loop never fills one tape, but it also replaces the earliest evidence.

Where you’ve seen it

In practice, logging: { driver: json-file, options: { max-size: 10m, max-file: "3" } }; df -h /var/lib/docker is the concrete move for this job: configure max-size and max-file so container logs cannot fill the disk. The release is not accepted until produce enough lines to rotate at least once, count only three files and alert before /var/lib/docker reaches the threshold confirms the result.

Words you’ll hear

max-size
The implementation control in logging: { driver: json-file, options: { max-size: 10m, max-file: "3" } }; df -h /var/lib/docker for configure max-size and max-file so container logs cannot fill the disk.
max-file
The result to observe with produce enough lines to rotate at least once, count only three files and alert before /var/lib/docker reaches the threshold, rather than infer from a successful command alone.
Rotation
The production boundary exposed when multiplying only by max-size and forgetting max-file/replica count, or leaving a remote logging driver configured under an option it ignores.

Visual diagram

Loading interactive diagram

Theory & deep dive

max-size control path

The concrete mechanism is logging: { driver: json-file, options: { max-size: 10m, max-file: "3" } }; df -h /var/lib/docker. The observable result is produce enough lines to rotate at least once, count only three files and alert before /var/lib/docker reaches the threshold; if those disagree, inspect the runtime evidence before changing unrelated settings.

Configure max-size and max-file so container logs cannot fill the disk. Keep max-size, max-file and Rotation in the same deployment record so the intent and the observed state cannot drift apart.

Concrete max-size setup

logging: { driver: json-file, options: { max-size: 10m, max-file: "3" } }; df -h /var/lib/docker

Key takeaway: Prove max-file with produce enough lines to rotate at least once, count only three files and alert before /var/lib/docker reaches the threshold, not with command success alone.

Rotation failure boundary

A 100m × 10 policy on twenty replicas is gigabytes, while one unbounded chatty service still fills the disk if the driver is not compatible. Rotation can delete the exact incident log that was too far in the past, so export important events centrally. The narrow failure to design for is multiplying only by max-size and forgetting max-file/replica count, or leaving a remote logging driver configured under an option it ignores.

Accept this compromise explicitly: Three to five small files preserve recent local diagnosis; central retention is better for audit and multi-host incident timelines. The controlled check-produce enough lines to rotate at least once, count only three files and alert before /var/lib/docker reaches the threshold-also identifies the point where a different design is safer.

Deliberate failure test

Exercise this failure safely: multiplying only by max-size and forgetting max-file/replica count, or leaving a remote logging driver configured under an option it ignores.

Key takeaway: Three to five small files preserve recent local diagnosis; central retention is better for audit and multi-host incident timelines.

How it works, step by step

Step 1 of 4
Design

1. State the boundary

Write down why the workload needs this: A 100m × 10 policy on twenty replicas is gigabytes, while one unbounded chatty service still fills the disk if the driver is not compatible. Rotation can delete the exact incident log that was too far in the past, so export important events centrally.

Set bounded log policy in daemon or Compose defaults and alert on host free bytes, inodes and logging errors.
Key numbers at this step
Intent
max-size

When to use it & trade-offs

What it is

max-size limits each active/archived local log file and max-file limits retained count. Worst-case host usage is roughly services × replicas × both limits, and Docker must have permission to rotate the log stream before free-space exhaustion.

Why it matters: A 100m × 10 policy on twenty replicas is gigabytes, while one unbounded chatty service still fills the disk if the driver is not compatible. Rotation can delete the exact incident log that was too far in the past, so export important events centrally.

When to reach for it

  • The fit is strongest for this job: configure max-size and max-file so container logs cannot fill the disk. Pair it with produce enough lines to rotate at least once, count only three files and alert before /var/lib/docker reaches the threshold in the runbook.
  • Production max-size changes should make max-file observable through logging: { driver: json-file, options: { max-size: 10m, max-file: "3" } }; df -h /var/lib/docker, rather than trusting the runtime default.
  • Keep a rollback example for the case where multiplying only by max-size and forgetting max-file/replica count, or leaving a remote logging driver configured under an option it ignores.

When to avoid or be careful

  • Do not accept command success while the system can still fail by multiplying only by max-size and forgetting max-file/replica count, or leaving a remote logging driver configured under an option it ignores.
  • Avoid erasing Rotation protection merely to dodge this cost: “Three to five small files preserve recent local diagnosis; central retention is better for audit and multi-host incident timelines”.
  • Do not replace the evidence path-produce enough lines to rotate at least once, count only three files and alert before /var/lib/docker reaches the threshold-with a screenshot or a mutable tag.

logging: { driver: json-file, options: { max-size: 10m, max-file: "3" } }; df -h /var/lib/docker: practical choices

Explicit max-size
Best for: Configure max-size and max-file so container logs cannot fill the disk, with a reviewed runbook.

Strengths: max-size limits each active/archived local log file and max-file limits retained count. Worst-case host usage is roughly services × replicas × both limits, and Docker must have permission to rotate the log stream before free-space exhaustion.

Watch out: Three to five small files preserve recent local diagnosis; central retention is better for audit and multi-host incident timelines.

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

Strengths: It can begin with logging: { driver: json-file, options: { max-size: 10m, max-file: "3" } }; df -h /var/lib/docker and fewer surrounding controls.

Watch out: It silently accepts multiplying only by max-size and forgetting max-file/replica count, or leaving a remote logging driver configured under an option it ignores, which makes the result hard to reproduce after promotion.

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

Strengths: A 100m × 10 policy on twenty replicas is gigabytes, while one unbounded chatty service still fills the disk if the driver is not compatible. Rotation can delete the exact incident log that was too far in the past, so export important events centrally.

Watch out: The platform adds an ownership and debugging layer; retain produce enough lines to rotate at least once, count only three files and alert before /var/lib/docker reaches the threshold as the direct check.

Interview signals & numbers to know

When this topic comes up

  • logging: { driver: json-file, options: { max-size: 10m, max-file: "3" } }; df -h /var/lib/docker
  • produce enough lines to rotate at least once, count only three files and alert before /var/lib/docker reaches the threshold
  • Failure signature: multiplying only by max-size and forgetting max-file/replica count, or leaving a remote logging driver configured under an option it ignores
  • Trade-off: Three to five small files preserve recent local diagnosis; central retention is better for audit and multi-host incident timelines.

Benchmarks & rules of thumb

10 MB -
maximum file in the example
3 files -
retained including the active log
30 MB -
nominal per-container upper bound

Common mistakes & follow-ups

Common interview mistakes

  • Treating a successful logging: { driver: json-file, options: { max-size: 10m, max-file: "3" } }; df -h /var/lib/docker as proof and skipping produce enough lines to rotate at least once, count only three files and alert before /var/lib/docker reaches the threshold.
  • Multiplying only by max-size and forgetting max-file/replica count, or leaving a remote logging driver configured under an option it ignores
  • Optimizing max-size without accepting that three to five small files preserve recent local diagnosis; central retention is better for audit and multi-host incident timelines.

Likely interviewer follow-ups

  • Why does logging: { driver: json-file, options: { max-size: 10m, max-file: "3" } }; df -h /var/lib/docker address max-size here rather than through application code?
  • How would you distinguish healthy max-file from the failure “multiplying only by max-size and forgetting max-file/replica count, or leaving a remote logging driver configured under an option it ignores” using produce enough lines to rotate at least once, count only three files and alert before /var/lib/docker reaches the threshold?
  • When would this trade-off-“Three to five small files preserve recent local diagnosis; central retention is better for audit and multi-host incident timelines”-justify a different Rotation design?
Interview tip: Give one concrete operation-logging: { driver: json-file, options: { max-size: 10m, max-file: "3" } }; df -h /var/lib/docker-and one proof-produce enough lines to rotate at least once, count only three files and alert before /var/lib/docker reaches the threshold. Then name the boundary: multiplying only by max-size and forgetting max-file/replica count, or leaving a remote logging driver configured under an option it ignores.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Preventing Disk Exhaustion via Log Rotation (max-size, max-file) with generative AI interview Q&A and hands-on practice.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Production Logging Drivers (json-file, local, syslog, fluentd, awslogs)
Next topic
Centralized Log Aggregation (Grafana Loki, ELK Stack, Promtail)