https://github.com/vegardit/docker-traefik-logrotate
Lightweight Docker image to be used in conjunction with a dockerized Traefik instance to rotate Traefik's access logs.
https://github.com/vegardit/docker-traefik-logrotate
docker-image logrotate traefik
Last synced: 6 days ago
JSON representation
Lightweight Docker image to be used in conjunction with a dockerized Traefik instance to rotate Traefik's access logs.
- Host: GitHub
- URL: https://github.com/vegardit/docker-traefik-logrotate
- Owner: vegardit
- License: apache-2.0
- Created: 2021-07-14T18:27:37.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-12-17T20:45:17.000Z (11 months ago)
- Last Synced: 2025-01-15T02:59:02.726Z (10 months ago)
- Topics: docker-image, logrotate, traefik
- Language: Shell
- Homepage: https://buymeacoffee.com/vegardit
- Size: 48.8 KB
- Stars: 53
- Watchers: 4
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[](https://github.com/vegardit/docker-traefik-logrotate/actions?query=workflow%3ABuild)
[](#license)
[](https://hub.docker.com/r/vegardit/traefik-logrotate)
[](https://hub.docker.com/r/vegardit/traefik-logrotate)
[](CODE_OF_CONDUCT.md)
1. [What is it?](#what-is-it)
1. [Usage](#usage)
1. [License](#license)
A lightweight, multi-arch Docker image based on [alpine:3](https://hub.docker.com/_/alpine/tags?name=3) to be used in conjunction with
a dockerized [Traefik](https://traefik.io) instance to rotate [Traefik's access logs](https://doc.traefik.io/traefik/observability/access-logs/).
Automatically rebuilt **weekly** to include the latest OS security fixes.
Example `docker-compose.yml`:
```yaml
services:
traefik:
image: traefik:latest
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /var/log/traefik:/var/log/traefik:rw # folder containing access.log file
deploy:
restart_policy:
condition: on-failure
delay: 5s
# ... other configurations
logrotate:
image: vegardit/traefik-logrotate:latest
volumes:
- /var/run/docker.sock:/var/run/docker.sock:rw # required to send USR1 signal to Traefik after log rotation
- /var/log/traefik:/var/log/traefik:rw # folder containing access.log file
environment:
TZ: "Europe/Berlin"
# all environment variables are optional and show the default values:
LOGROTATE_LOGS: "/var/log/traefik/*.log" # log files to rotate, directory must match volume mount
LOGROTATE_TRIGGER_INTERVAL: daily # rotate daily, must be one of: daily, weekly, monthly, yearly
LOGROTATE_TRIGGER_SIZE: 50M # rotate if log file size reaches 50MB
LOGROTATE_MAX_BACKUPS: 14 # keep 14 backup copies per rotated log file
LOGROTATE_START_INDEX: 1 # first rotated file is called access.1.log (ignored when dateext is enabled)
LOGROTATE_USE_DATEEXT: false # use date extension instead of numbers (e.g., access.log-20240814)
LOGROTATE_DATEFORMAT: "-%Y%m%d" # date format for rotated files when dateext is enabled
LOGROTATE_FILE_MODE: 0644 # file mode of the rotated file
LOGROTATE_FILE_USER: root # owning user of the rotated file
LOGROTATE_FILE_GROUP: root # owning group of the rotated file
CRON_SCHEDULE: "* * * * *"
CRON_LOG_LEVEL: 8 # see https://unix.stackexchange.com/a/414010/378036
# command to determine the id of the container running Traefik:
TRAEFIK_CONTAINER_ID_COMMAND: docker ps --no-trunc --quiet --filter label=org.opencontainers.image.title=Traefik
deploy:
restart_policy:
condition: on-failure
delay: 5s
```
### Date-based Log Rotation
To use date-based naming for rotated files instead of numbered suffixes, enable the `dateext` option:
```yaml
services:
logrotate:
image: vegardit/traefik-logrotate:latest
volumes:
- /var/run/docker.sock:/var/run/docker.sock:rw
- /var/log/traefik:/var/log/traefik:rw
environment:
LOGROTATE_USE_DATEEXT: "true" # Enable date-based naming
LOGROTATE_DATEFORMAT: "-%Y%m%d" # Results in: access.log-20240814.gz
# Alternative formats:
# LOGROTATE_DATEFORMAT: ".%Y-%m-%d" # Results in: access.log.2024-08-14.gz
# LOGROTATE_DATEFORMAT: "_%Y%m%d_%H" # Results in: access.log_20240814_15.gz (hourly)
```
When `LOGROTATE_USE_DATEEXT` is enabled:
- Rotated files will be named with dates (e.g., `access.log-20240814.gz`)
- The `LOGROTATE_START_INDEX` setting is ignored
- Files are sorted lexically, so use year-month-day format for proper ordering
- Supported format specifiers: `%Y` (year), `%m` (month), `%d` (day), `%H` (hour), `%M` (minute), `%S` (second)
All files in this repository are released under the [Apache License 2.0](LICENSE.txt).
Individual files contain the following tag instead of the full license text:
```
SPDX-License-Identifier: Apache-2.0
```
This enables machine processing of license information based on the SPDX License Identifiers that are available here: https://spdx.org/licenses/.