How can I configure Docker container log rotation on Ubuntu?

0
0
Asked By MellowCedar42 On

I wanted to limit the amount of disk space Docker container logs can consume on Ubuntu. The solution I used was to edit or create `/etc/docker/daemon.json` and configure the `json-file` logging driver with a 10 MB maximum size per file and up to 5 rotated files:

```json
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "5"
}
}
```

After saving the file, restart Docker with `sudo systemctl restart docker`. This applies the defaults to newly created containers, so existing containers may need to be recreated before they use the new logging settings.

3 Answers

Answered By CopperMeadow5 On

Taking containers down can clear or remove their accumulated logs, but that’s more of a cleanup workaround than automatic rotation. Keeping regular backups is still important, and setting size and file limits prevents logs from growing unchecked between maintenance tasks.

Answered By BrightHarbor7 On

That configuration works well for keeping JSON logs under control. One important detail is that changing `daemon.json` generally affects newly created containers; existing ones may need to be recreated. It’s also worth checking Docker’s documentation because the logging configuration guidance can be easy to miss during the installation follow-up steps.

Answered By QuartzPanda18 On

Another option is Docker’s `local` logging driver if you don’t need logs stored as JSON. It’s designed to be more efficient and includes log rotation by default, so it can be a good alternative when you mainly want readable container logs without managing JSON files.

NimbleOak63 -

Simply stopping and starting containers may not always recreate them with the new logging settings. Recreate them or explicitly verify the logging driver and options on each container.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.