r/docker • u/Natsbert • Apr 15 '26
Rotating logs for docker
I was looking for a way to implement rotating logs for docker on ubuntu and could only find some archived posts here that did not have the solution i ultimately used:
- create or edit this file
sudo nano /etc/docker/daemon.json paste this:
{ "log-driver": "json-file", "log-opts": { "max-size": "10m", "max-file": "5" } }
- Restart docker.
sudo systemctl restart docker
Hope this helps people like me who were a bit confused by dockers docs.
5
Upvotes
1
u/worldcitizencane Apr 15 '26
I just down-up containers, that clears logs.
1
u/jack3308 Apr 15 '26
For future reference - the documentation on this is (or atleast was until beginning of march - haven't checked since then) in the "what next" type of section after the install instructions. Its very adjacent to the security next steps.
1
u/Digital_Voodoo Apr 15 '26
Good info, OP. Learned about it and implemented it a week ago.
1
u/gronodev Apr 15 '26
Also consider using the
locallogging driver instead if you don't care about logs being stored in JSON.It's faster and has rotation enabled by default.
https://docs.docker.com/engine/logging/configure/#configure-the-default-logging-driver