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.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay