How to configure container log rotation for the Docker daemon
Article Number: 000020141
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
- Edit the Docker daemon configuration file:
$ vim /etc/docker/daemon.json
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "10"
}
}
$ 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.