---
title: "Cap the size of container logs · Agent Wranglers"
url: https://agentwranglers.se/playbook/operations/containers/container-log-rotation
updated: 2026-10-21
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Cap the size of container logs

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Containers](https://agentwranglers.se/playbook/operations/containers.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers). Updated 2026-10-21.

- Level: Required
- Chapter: [Containers](https://agentwranglers.se/playbook/operations/containers)
- Rule: Give every container's logs a size limit and a file count, so one chatty container cannot fill the disk.
- Risk: The app down or unusable
- How: Docker's default `json-file` driver does not rotate logs, and a container with much output can fill the disk. Set the default driver to `local`, which keeps five files of 20 MB each by default. Or keep `json-file` and set `max-size` and `max-file`. Existing containers keep the settings they were created with, so recreate them after the change. Disk alerts come from [Warn before resources run out](https://agentwranglers.se/playbook/operations/capacity-and-cost/exhaustion-alerts).
- Check: `docker info --format '{{.LoggingDriver}}'` prints `local`, or every running container's `docker inspect --format '{{.HostConfig.LogConfig}}'` shows a `max-size`.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### JSON example

```json
{
  "log-driver": "local"
}
```

### YAML example

```yaml
services:
  web:
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "3"
```

## Sources

- [Docker logging driver configuration](https://docs.docker.com/engine/logging/configure/)
- [Docker local logging driver](https://docs.docker.com/engine/logging/drivers/local/)

## Related rules

- [Warn before resources run out](https://agentwranglers.se/playbook/operations/capacity-and-cost/exhaustion-alerts) in Operations

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/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 playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Put each container only on the networks it needs](https://agentwranglers.se/playbook/operations/containers/container-networks)
- [Containers](https://agentwranglers.se/playbook/operations/containers)
