Skip to content

Wipe clean logfile on daily basis with logrotate

I want to clean a Docker container logs every day (no need to store/archive the data). I created a file called docker in /etc/logrotate.d and put the following inside:

/var/lib/docker/containers/*/*.log {
  rotate 0      #do not keep archives
  copytruncate  #continue working in the same log file

well, but it doesn’t work. So, obviously something in my logrotate configuration isn’t right. AFAIK, I don’t need to setup crontab for this. Is my configuration wrong? Is there anything that I am missing?

Is there a way to run and test logrotate without having to wait a day?



rotate 0 is redundant here, 0 is the default for rotation, which means, no rotation and old ones are removed.

You can test it using,

$ logrotate -f /etc/logrotate.d/docker

It might be better to test it by putting rotate 1 and then with rotate 0 to check if logrotate is functioning correctly.

If logrotate is installed correctly, then one would have a crontab entry in /etc/cron.daily/logrotate. This file reads the configuration file /etc/logrotate.conf which includes anything under /etc/logrotate.d


User contributions licensed under: CC BY-SA
4 People found this is helpful