DEV Community

Cover image for Change Docker default logging driver
Sergio Peris
Sergio Peris

Posted on • Originally published at sertxu.dev

Change Docker default logging driver

Docker by default uses the json-file logging driver. This driver stores the logs in a JSON-formatted file, that makes it easy to access the logs programatically.

But this json-file driver has one problem, it doesn’t performs log rotation by default, due to that this can cause disk exhaustion.

To solve this we have two options, enable the log rotation to this driver or change the driver to another driver.

Enable log rotation to json-file driver

We can enable the log rotation at the /etc/docker/daemon.json file.

{
    "log-driver": "json-file",
    "log-opts": {
        "max-size": "10m",
        "max-file": "5"
    }
}
Enter fullscreen mode Exit fullscreen mode

Change to local driver

The local driver is newer than the json-file driver, and it might become the default one in the future. It has log rotation enabled by default.

{
    "log-driver": "local",
}
Enter fullscreen mode Exit fullscreen mode

Restart Docker to apply changes

Once we’ve decided what logging driver to use, we should restart the Docker service in order to apply the changes.

systemctl restart docker
Enter fullscreen mode Exit fullscreen mode

Keep in mid our existing container won’t change to our new logging configuration until they’re recreated.

Top comments (0)