Skip to main content
InterviewHubPRO
Section Overview
Q23

Question 23 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

46%
Docker & Containers (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

How does Docker logging work and how do you prevent log files from exhausting host disk space?

senior LevelMost AskedCode ExampleDocker & ContainersSystem Design

In Simple Words: By default, Docker captures all stdout and stderr streams from PID 1 and writes them as JSON files to /var/lib/docker/containers/<id>/<id>-json.log. Without log rotation, a chatty application will eventually consume 100% of host disk space, crashing the server!

Configuring Global Log Rotation (/etc/docker/daemon.json):

json
{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "50m",
    "max-file": "3"
  }
}

Limits logs to 3 files of 50MB each (150MB maximum per container).