Add Configurable Log Rotation and Max Log Size for Docker Containers

Problem/Justification

Currently, TrueNAS does not provide configuration options for automatic log rotation or maximum log size limits for Docker containers. As a result, container logs can grow indefinitely, consuming disk space and potentially affecting system performance. Users must manually manage and clean up logs, which is inefficient and error-prone.

Impact

This feature would improve reliability and ease of maintenance for all TrueNAS users running Docker containers. By allowing administrators to configure log size limits and rotation policies, users can prevent uncontrolled log growth and ensure more predictable storage usage. The change would align TrueNAS with common best practices seen in standalone Docker setups. Potential downsides are minimal, as the settings could be optional.

User Story

A TrueNAS user runs several Docker containers that produce continuous logs. Within the container configuration interface, the user sets a maximum log file size and rotation policy (e.g., rotate when reaching 100 MB, keep last 3 rotations). TrueNAS automatically applies these settings, ensuring logs remain manageable without manual interventi

Technical Details / Implementation Notes

  • Leverage Docker daemon log driver options:
    max-size for specifying the maximum size of a single log file before rotation (e.g., max-size=100m ).
    max-file for defining the number of rotated log files to keep (e.g., max-file=3 ).
  • Integrate these settings into the TrueNAS Docker container configuration UI and API.
  • Ensure settings persist across container restarts and updates.
  • Provide an optional global default under system-level Docker configuration, inheritable by all containers.
  • Validate changes through the TrueNAS middleware to ensure consistent and predictable Docker behavior.
1 Like