Docker container logs can quietly consume a lot of disk. Do you set rotation on each host, in each Compose stack, or ship logs elsewhere and keep local retention small?
How do you keep container logs from filling up disks across hosts?
Answers
I'd use the local logging driver as the host default unless there's a reason to keep json-file. It rotates and compresses logs by default, with roughly 100 MiB of storage per container under its default settings.
Docker logs still works with the local driver. Set the default in daemon.json and recreate existing containers to pick it up. Changing the daemon default doesn't retrofit containers that already exist.
Reply to this answer
A json-file limit is perfectly workable too. Set max-size and max-file in daemon.json as a baseline on every host. For example, 50m and 3 gives each container up to three log files of roughly 50 MiB each.
Those options need to be strings in daemon.json. Budget for the number of containers on the host, not just one, and remember that the new default only applies when containers are created.
Reply to this answer
Put a logging block in Compose when the limits belong with the service. That way the stack carries its settings to another host instead of depending on whatever default happens to be there.
A reusable YAML anchor can keep the same settings from being repeated for every service. You still need to recreate existing containers for changed logging settings to take effect.
Reply to this answer
For longer history, ship logs to a central store and keep the host retention short. One option is journald with a collector forwarding entries to a log store. Configure and check the journal's own storage limits rather than assuming all journals are volatile.
Watch out for noisy containers. If the local journal rotates faster than the collector can keep up, you could lose the history you meant to retain.
9x+Mordeli:
That helps. Short local retention sounds useful, but only if forwarding keeps up when a container gets noisy.
Reply to this answer
Add your answer
Answers are reviewed before publication.
9q+Vetri:
Containers with their own logging configuration can override that baseline, so it's worth checking those too.