SUSE Support

Here When You Need Us

How to configure container log rotation for the Docker daemon

This document (000020141) is provided subject to the disclaimer at the end of this document.

Environment

Rancher 2.x
RKE
Docker


Situation

Task

As the default setting on Docker is to log using the json-file log driver, without a container log limit, this can lead to disk-fill events on nodes. This article provides steps to configure any nodes running Docker to have a limited container log size and rotate out older container logs.

Pre-requisites

  • Node(s) running Docker, using the json-file log driver
  • Permission to edit the /etc/docker/daemon.json and to restart the Docker daemon

Warning

  • You must restart the Docker daemon for the changes to take effect for newly created containers
  • As the container logging configuration for pre-existing container is immutable, existing containers do not use the new logging configuration and will need to be redeployed to take on this new configuration.

 

Resolution

Resolution

  1. Edit the Docker daemon configuration file:

    $ vim /etc/docker/daemon.json
  2. Add the following lines to the file, to configure a maximum container log file size of 10MB and maintain only 10 of these before deleting the oldest:

    {  
      "log-driver": "json-file",  
      "log-opts": {
        "max-size": "10m",
        "max-file": "10"  
      }
    }
  3. Restart the docker daemon to apply the settings to new containers (see Warnings above):

    $ systemctl restart docker

Tips

You could include this Docker daemon container log rotation configuration in your build/connfiguration management systems, to ensure this is automatically applied to nodes on provisioning, removing any requirement for manual configuration.

Further reading

Docker JSON file log driver documentation

Disclaimer

This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.

  • Document ID:000020141
  • Creation Date: 11-Mar-2024
  • Modified Date:11-Mar-2024
    • SUSE Rancher

< Back to Support Search

For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com

SUSE Support Forums

Get your questions answered by experienced Sys Ops or interact with other SUSE community experts.

Support Resources

Learn how to get the most from the technical support you receive with your SUSE Subscription, Premium Support, Academic Program, or Partner Program.

Open an Incident

Open an incident with SUSE Technical Support, manage your subscriptions, download patches, or manage user access.