Skip to content

Logrotate in an Alpine Linux docker container

License

Notifications You must be signed in to change notification settings

camunda/infra-logrotate

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logrotate

This is a docker container based on Alpine Linux with logrotate.

Configuration

Simply mount a directory with your logs into the container at /logs and optionally configure some logrotation features with the following environment variables:

  • LOGROTATE_FILE_PATH (default var/log): File path to observe
  • LOGROTATE_FILE_PATTERN (default: *.log): File pattern within the /var/log directory for logs to be rotated by logrotate
  • LOGROTATE_TRUNCATE (default: copytruncate): Truncation behaviour of logrotate, use either copytruncate or nocopytruncate
  • LOGROTATE_COMPRESS (default: nocompress): Compression behaviour for rotated files, use either nocompress or compress
  • LOGROTATE_ROTATE (default: 5): The rotate option of logrotate
  • LOGROTATE_SIZE (default 50M): the size option of logrotate
  • LOGROTATE_POSTROTATE (default: echo 'test'): run script after rotation

If you want to use a different logrotate configuration, mount a logrotate.conf at /etc/logrotate.conf into the container. The environment variables mentioned above have no effect if you supply your own logrotate configuration file.

By default, logrotate is run periodically every 15 minutes. You can override the cron schedule with the environment variable LOGROTATE_CRON. Use one of Alpine Linux' predefined periods (15min, hourly, daily, weekly or monthly) or specify a cron schedule expression like 5 4 * * * (at 04:05 every day). If you are unsure about the cron schedule expression syntax, consult a tool like crontab guru.

Examples

docker run \
  -v /path/to/my/logs:/logs \
  -e LOGROTATE_FILE_PATTERN="*.log" \
  # don't rotate at all but truncate logs when they exceed the configured rotation size
  -e LOGROTATE_ROTATE="0" \
  # run logrotate every 5 minutes
  -e LOGROTATE_CRON="*/5 0 0 0 0" \
  linkyard:logrotate

Attribution

This image is somewhat similar to the no longer maintained blacklabelops/logrotate but a lot simpler to use and maintain.

Forked from linkyard/docker-logrotate

About

Logrotate in an Alpine Linux docker container

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 79.1%
  • Dockerfile 20.9%