OPS-65Required
Cap the size of container logs
Give every container's logs a size limit and a file count, so one chatty container cannot fill the disk.
How to do it
Docker's default json-file driver does not rotate logs, and a container with much output can fill the disk. Set max-size and max-file for json-file as the default in the daemon settings. A log shipper can tail those files. Docker's local driver also rotates, but its files are for the daemon alone, so use it only when nothing reads the files. Existing containers keep the settings they were created with, so recreate them after the change. Disk alerts come from Warn before resources run out.
Examples
JSON example
{
"log-driver": "local"
}
YAML example
services:
web:
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
How to check
Every running container's docker inspect --format '{{.HostConfig.LogConfig}}' shows a max-size and a max-file, or the local driver with no shipper reading its files.
Sources
Related rules
- OPS-42 Warn before resources run out in Operations and observability
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/operations/containers/container-log-rotation">Agent Wranglers operations and observability playbook</a>. In code you write, add a comment next to it with the same link.