Tips > Ops & Security

Configure Log Rotation to Prevent Disk Fill

Docker's default `json-file` logging driver stores container logs with no size limit.

TipAdvanced2 min read

Docker's default json-file logging driver stores container logs with no size limit. On a busy n8n instance with verbose execution logging, container logs can consume tens of gigabytes within weeks, silently filling the disk until the host becomes unresponsive. Setting max-size and max-file at the container level caps log storage with automatic rotation.

Real-world example: You limit each container to 3 log files of 50 MB each, capping total log storage at 150 MB per container.

services:
  n8n:
    image: n8nio/n8n:1.94.1
    restart: unless-stopped
    logging:
      driver: json-file
      options:
        max-size: "50m"
        max-file: "3"
        tag: "n8n"

  postgres:
    image: postgres:16-alpine
    restart: unless-stopped
    logging:
      driver: json-file
      options:
        max-size: "20m"
        max-file: "3"
        tag: "postgres"
```text
Alternatively, set the default for all containers in the Docker daemon configuration:

```json title="/etc/docker/daemon.json"
{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "50m",
    "max-file": "3"
  }
}
```text
```bash

# Apply the daemon configuration change

sudo systemctl restart docker
```text
> **Warning: Existing Containers**
>
> Changing `daemon.json` only affects newly created containers. Existing containers keep their original logging configuration. You must recreate them with `docker compose up -d --force-recreate` to pick up the new defaults.

This prevents a common silent failure where the disk fills up, causing PostgreSQL to crash, n8n to lose data, and the host to become unreachable via SSH.

**Related:** [Set a Unique Encryption Key and Back It Up](../security-best-practices/01-set-a-unique-encryption-key-and-back-it-up.md) | [Configure Payload Size and Binary Data Mode for Large Files](../performance-and-large-files/01-configure-payload-size-and-binary-data-mode-for-large-files.md)

Want this running in your stack?

I build production n8n and Cloudflare automation for teams — the same engineering behind HarperFlow. Fixed-price, escrow-protected, US-based.