A small side-car container that discovers log files and rotates them using the standard logrotate utility. It is intended to be attached to workloads that write logs to disk and need automated rotation/retention.
This fork modernizes the project and bringt up to date containers.
This container:
- Generates a logrotate configuration based on environment variables.
- Runs logrotate on a schedule (interval or cron schedule).
- Supports compression, size thresholds, custom olddir, statusfile and scripts to run before/after rotation.
Rotate Docker container logs (daily, keep 5 rotations):
docker run -d \
-v /var/lib/docker/containers:/var/lib/docker/containers \
-v /var/log/docker:/var/log/docker \
-e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
ghcr.io/lazybytez/logrotate-containerRotate hourly:
docker run -d \
-v /var/lib/docker/containers:/var/lib/docker/containers \
-v /var/log/docker:/var/log/docker \
-e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
-e "LOGROTATE_INTERVAL=hourly" \
ghcr.io/lazybytez/logrotate-containerDocker Compose example:
services:
logrotate:
image: ghcr.io/lazybytez/logrotate-container:latest
environment:
LOGS_DIRECTORIES: /config/log/app/
LOGROTATE_INTERVAL: daily
LOGROTATE_SIZE: 1G
volumes:
- app_data:/configLOGS_DIRECTORIES(required) - space separated directories to scan, e.g. "/var/log /var/lib/docker/containers"LOG_FILE_ENDINGS- space separated file extensions (default: "log")LOGROTATE_INTERVAL- hourly|daily|weekly|monthly|yearly (affects logrotate rules)LOGROTATE_CRONSCHEDULE- cron expression for the schedule; default is suitable for intervalLOGROTATE_COPIES- number of rotated copies to keep (default 5)LOGROTATE_SIZE- trigger rotate when file exceeds size (e.g. 100k, 10M)LOGROTATE_COMPRESSION- set to "compress" to enable compressionLOGROTATE_DELAYCOMPRESS- "false" to disable default delaycompress (when compression enabled)LOGROTATE_MODE- e.g. "create 0644" to change rotate mode (default: copytruncate)LOGROTATE_OLDDIR- directory to move old logs intoLOGROTATE_STATUSFILE- path to logrotate status fileLOGROTATE_PARAMETERS- raw flags passed to logrotate (e.g. "vdf")LOGROTATE_PREROTATE_COMMAND/LOGROTATE_POSTROTATE_COMMAND- scripts/commands to runLOGROTATE_AUTOUPDATE- regenerate logrotate configuration on each cron execution
- To capture Docker JSON logs: set LOGS_DIRECTORIES to /var/lib/docker/containers and mount that path into the container.
- To keep rotated logs in a separate volume: mount a host dir and set LOGROTATE_OLDDIR to that mount point.
- If compression is enabled but you want the newest rotated file compressed immediately: set LOGROTATE_DELAYCOMPRESS=false.
- Containers in read-only mode are not supported (this image generates a logrotate configuration on startup).
- Check the cron log (if you configured LOG_FILE) and the logrotate logfile (LOGROTATE_LOGFILE).
- Ensure mounted paths are accessible by the container user.
- Use LOGROTATE_PARAMETERS=v or vf to troubleshoot behavior without making changes.
- Ensure the container is not running in read-only mode.
If you want to take part in contribution, like fixing issues and contributing directly to the code base, please visit the How to Contribute document.