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//. Without limits, these files grow unbounded.
Want to master this scenario in a live sandbox? KodeKloud's Docker Certified Associate (DCA) Hands-On Lab Course covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: "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."
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
- 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.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
-
Structuring Dockerfile instructions inefficiently by copying app source before package manifests when configuring container running Nginx
Copying code before package manifests (
package.json,go.mod,requirements.txt) invalidates the build cache on every commit, forcing slow full reinstalls. -
Neglecting the PID 1 process reap problem and omitting proper SIGTERM signal forwarding when configuring container running Nginx
If an application runs as PID 1 without an init system (like
tini), it fails to reap zombie child processes and ignoresSIGTERMsignals, causing unclean 10s timeouts. - Assembling single-stage images containing compilers, build SDKs, and header files in production when configuring container running Nginx Single-stage builds bloat image size by gigabytes and expose extensive package vulnerabilities; multi-stage builds isolate artifacts into minimal distroless images.
- Confusing container port forwarding on bridge networks with unisolated host networking mode when configuring container running Nginx Bridge networking utilizes iptables NAT translations which add latency overhead, whereas host networking bypasses the network namespace entirely.