Simple docker container that does logrotate. Designed as sidecar container for Kubernetes pods that write logfiles but don't do rotation themselves.
- You most likely don't want to keep a ton of old log files in a running pod
- The purpose of this is solely to ensure logs don't fill up the disk - not long-term archival
- Instead, use a sidecar to
tailthe active log and let the K8S log collector handle the rest
- Use shared volumes to share log files with a container that produces logfiles
- Set
LOGROTATE_PATTERNetc. to configure what logrotate watches, log file size, etc. - See docker-compose.yaml for a sample app
docker run -it --rm \ --env CRON_SCHEDULE='' \ --env LOGROTATE_SIZE=1M \ --env LOGROTATE_PATTERN=/myapp/logs/*.log \ -v logs:/myapp/logs quay.io/honestbee/logrotate-
Starts a small sample app that writes a logfile and rotates it:
docker-compose up
Most options below are substituted into the config file for logrotate, so please refer to the Manpage for logrotate for detailled documentation.
| Option | Default | Description |
|---|---|---|
CRON_SCHEDULE | 0 * * * * | Cron schedule for logrotate command |
LOGROTATE_SIZE | 100M | Maximum size of log files |
LOGROTATE_MODE | copytruncate | Mode of log rotation |
LOGROTATE_PATTERN | /logs/*.log | Path pattern of log files to manage |
LOGROTATE_ROTATE | 0 | Number of old log files to keep |
SU_CONFIG | root root | Su user group |
MAX_AGE | 2 | Number of days to keep the log files |
blacklabelops/logrotate allows more configuration options but was not chosen on grounds of the images not being controlled by us and the sensitive nature of logs.