logrotate inside docker?

I think there were talks on integrating logrotate for docker containers.
Since logging to a file of 10GB+ of size add high cpu usage and such.

But I see now in docker logs for a container:

# docker logs inc_mainnet
reading config file /tmp/logrotate
error: /tmp/logrotate:3 unknown option 'secondly' -- ignoring line
error: /tmp/logrotate:8 unknown unit 'm'
error: found error in /data/*.txt , skipping
removing last 1 log configs
Reading state from file: /var/lib/logrotate.status
Allocating hash table for state file, size 64 entries
Handling 0 logs

probably someone tries incorporating logrotate which is good
but probably something is miss configured no?

1 Like

Hi @huglester,

I’m so happy to see that you share this issue with us. In the docker container, we added logrotate lib to save storage space

echo “/data/*.txt {
rotate 3
secondly
compress
missingok
delaycompress
copytruncate
size 100m
}” > /tmp/logrotate
logrotate -fv /tmp/logrotate

Somehow, it didn’t work in some cases. Let us check and reply after fixed this issue or replace by other lib. By the way, in your case, you can use this cmd to restart docker and reset log.txt file

‘sudo docker restart inc_mainnet’

Thank you very much.

2 Likes

Hello

docker exec -it inc_mainnet sh

}’ > /tmp/logrotate
~ # logrotate -fv /tmp/logrotate
reading config file /tmp/logrotate
error: /tmp/logrotate:3 unknown option ‘secondly’ – ignoring line
error: /tmp/logrotate:8 unknown unit ‘m’
error: found error in /data/*.txt , skipping
removing last 1 log configs
Reading state from file: /var/lib/logrotate.status
Allocating hash table for state file, size 64 entries

Handling 0 logs

  • error the same basically.

something like that would work I guess:
echo ‘/data/*.txt {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 644 root root
sharedscripts
}’ > /tmp/logrotate
logrotate -fv /tmp/logrotate

BUT! we need to kind of ‘reload’ daemon to start writing to new log.
so it would need to ‘reread’ log file path? or file socket. not sure.
because it would just continue writing to old file with different naming like log.txt.1