Log rotation limits disk usage by switching to a new log file when the current file reaches a configured size. Docker can retain a fixed number of files, then overwrite the oldest one. section 19.1
Configure rotation where it best fits the workload:
- Set Docker Engine defaults to apply the policy to every container. section 19.1
- Set options on one container to keep its logs small without changing other containers. section 19.1
- Choose a maximum size and file count; three 5 KB files retain a known per-container amount before overwriting older files. section 19.1
# run with log options and an app setting to write lots of logs:
docker run -d --name timecheck2 `
--log-opt max-size=5k --log-opt max-file=3 `
-e Timer__IntervalSeconds=1 `
diamol/ch19-timecheck:2e
# verify the log setup in the container:
docker container inspect `
--format='{{json .HostConfig.LogConfig}}' `
timecheck2
# wait for a few minutes
# check the logs:
docker container inspect --format='{{.LogPath}}' timecheck2
Run a container with max-size=5k and max-file=3, inspect its logging configuration, then locate the rotated log files. section 19.1
Recognizing rotated files
Docker may still show one JSON log path, but archived files use that path as a base with numbered suffixes. Listing the log directory reveals the retained files. section 19.1



