Skip to content
Shellbay

Containers · about 2 min · 5 steps

Limit Docker log size

Stops container logs from filling the disk: Docker keeps a few log files of limited size per container.

Runs on

  • Debian / Ubuntu: supported
  • RHEL / Fedora: supported
  • Alpine: supported

Before you start

  • Run the Docker Engine and Compose workflow first.

What it changes on your server

  • Sets log-opts max-size and max-file in /etc/docker/daemon.json, keeping your other settings (installs jq to merge them). A copy of the old file is kept.
  • Restarts Docker. New and recreated containers use the limit; existing ones keep their old settings until recreated.

What Shellbay asks you

  1. How much log to keep?

    Each container's log is split into files of at most this size (m = megabytes); the oldest is deleted when the limit is reached. 10m and 3 files keeps up to 30 MB per container.

    Largest log file
    One of: 10m, 20m, 50m, 100m. Default: 10m
    Files kept per container
    A whole number from 1 to 20. Default: 3

    Example: 10m, 3

Steps

  1. Check Docker and its settings
  2. Install jq to merge the settings
  3. Write the new settings
  4. Restart Docker
  5. Check the limits are in place

Shellbay checks the server before the first step, and stops at the first step that fails.

When it's done

  • New containers keep at most ‹files kept per container› log files of ‹largest log file› each. Recreate existing containers to apply it, e.g. docker compose up -d --force-recreate.
  • Containers without a restart policy were started again; check Docker status if one is missing.