Docker logging drivers

Topic: Containers core

Summary

Configure how container stdout/stderr are handled with --log-driver. Default is json-file. Use json-file with max-size and max-file to limit disk. Use this when managing container log growth or forwarding logs.

Intent: How-to

Quick answer

  • Default: json-file. Set in daemon.json or per container: docker run --log-driver json-file --log-opt max-size=10m --log-opt max-file=3 image.
  • Other drivers: syslog, journald, fluentd, awslogs. Use for central logging. Configure in daemon.json for default.
  • docker logs works with json-file and journald. With other drivers use the logging system to read logs.

Prerequisites

Steps

  1. Limit log size

    docker run --log-opt max-size=10m --log-opt max-file=3 image. Or in daemon.json under log-driver and log-opts.

  2. Use another driver

    docker run --log-driver journald image. Or syslog, fluentd. Configure driver options as needed.

  3. Verify

    docker logs container (json-file/journald). Check disk usage; confirm rotation or forwarding.

Summary

Set log-driver and log-opts to limit size or forward logs; use json-file max-size/max-file to avoid disk fill.

Prerequisites

Steps

Step 1: Limit log size

Use max-size and max-file for json-file; or set in daemon.json.

Step 2: Use another driver

Switch to journald, syslog, or fluentd if needed.

Step 3: Verify

Check docker logs and disk usage; confirm rotation.

Verification

  • Logs rotate or forward; disk under control.

Troubleshooting

Logs missing — Some drivers do not support docker logs; use external system. Disk full — Lower max-size and max-file.

Next steps

Continue to