How can I configure Docker container log rotation on Ubuntu?

August 18, 2026 3 answers
Asked by fold-over
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.

Answers

+one.more.detail
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.

FerryQueue: 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.

Reply to this answer
VAPOR PRESSURE
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.
Reply to this answer
!fare adjustment+
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.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions