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.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay