Q: After months of daily Docker builds, your production server's disk is full. You run `docker system prune -af` and reclaim some space, but the disk is still 90% full. `docker system df` shows minimal usage. Where is the hidden disk consumption?
docker system prune only removes objects tracked by the Docker daemon (images, containers, volumes, build cache).
/var/lib/docker internals.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third.""
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: "When containerizing our microservices stack, container lifecycle and resource management were critical. The interviewer is testing: overlay2 layer directory orphans, /var/lib/docker internals.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third."
Production Solution & Architecture
docker system prune only removes objects tracked by the Docker daemon (images, containers, volumes, build cache). If the Docker daemon crashed or was force-killed during container operations, orphaned layer directories can accumulate in /var/lib/docker/overlay2/ that the daemon no longer tracks. *Diagnosis:* Run du -sh /var/lib/docker/overlay2/ and compare with docker system df. A large discrepancy confirms orphaned layers. *Fix:* The safest approach is to stop the Docker daemon (systemctl stop docker), back up any critical volumes, and reset the storage entirely (rm -rf /var/lib/docker). Restarting Docker recreates the directory structure. Re-pull needed images. For prevention, ensure the Docker daemon shuts down gracefully and monitor /var/lib/docker disk usage independently.
- Immediate Triage: docker system prune only removes objects tracked by the Docker daemon (images, containers, volu
- 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 months daily Docker
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 months daily Docker
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 months daily Docker 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 months daily Docker Bridge networking utilizes iptables NAT translations which add latency overhead, whereas host networking bypasses the network namespace entirely.