Q: A container running Nginx generates enormous log files and eventually fills the disk on the Docker host. You want Docker to automatically handle log rotation without modifying the Nginx configuration. How?
Docker's default json-file logging driver stores container stdout/stderr as JSON files under /var/lib/docker/containers/<id>/. Without li...
#Docker #Must enable BuildKit #L2 #Containers #Linux
🎙️ Candidate Opening & Architectural Context
""In an interview, I explain how we diagnosed container runtime failures without guessing. The interviewer is testing: Docker logging driver configuration, log rotation.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third.""
Advertisement
🛠️ Production Runbook & Step-by-Step Resolution
1️⃣
Production Solution & Architecture
Docker's default json-file logging driver stores container stdout/stderr as JSON files under /var/lib/docker/containers/. Without limits, these files grow unbounded. Configure log rotation at the container level: Or set it globally in /etc/docker/daemon.json: This rotates logs at 50MB per file and keeps a maximum of 5 rotated files (250MB total per container). For Docker Compose, use the logging: key under each service. Note: changing the global config only affects *newly created* containers, not existing ones.
docker run --log-opt max-size=50m --log-opt max-file=5 nginx
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: Docker's default json-file logging driver stores container stdout/stderr as JSON files under /var/lib/docker/containers//. Without."
⚡ 60-Second Elevator Pitch Talking Points
- Immediate Triage: Docker's default json-file logging driver stores container stdout/stderr as JSON files under /v
- Run targeted verification commands before modifying configuration.
- Automate permanent guardrails (CI check, alerts, IaC policy) to prevent recurrence.
Advertisement