jinleileiking / logrotate

Image for sidecar containers that do log rotation

Home Page:https://hub.docker.com/r/skymatic/logrotate

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Logrotate

Simplified version of honestbee/logrotate, not configurable using environment variables. Instead a logrotate.conf file needs to be mounted into this container.

Updated to latest alpine image to fix some vulnerabilities.

Usage

  • Use shared volumes to add /etc/logrotate.conf into the container
  • Use shared volumes to share log files with a container that produces logfiles
  • Set CRON_SCHEDULE

Standalone

docker run -it --rm \
  --env CRON_SCHEDULE='* * * * *' \
  -v $(pwd)/example/logrotate.conf:/etc/logrotate.conf:ro \
  -v $(pwd)/example/logs:/logs \
  skymatic/logrotate
# now log to example/logs/example.log and see rotation on every 1MiB

Kubernetes

Example running logrotate as a sidecar for traefik:

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: logs
spec:
  # ...
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: configs
data:
  logrotate.conf: |
    /logs/traefik.log {
        rotate 5
        copytruncate
        size 100M
        missingok
        nocompress

        postrotate
            pkill -USR1 traefik
        endscript
    }
---
kind: Deployment
apiVersion: apps/v1
metadata:
  # ...
spec:
  # ...
  template:
    spec:
      # ...
      shareProcessNamespace: true # allows access to traefik's PID from sidecar
      containers:
      - name: traefik
        # ...
      - name: logrotate
        image: skymatic/logrotate:latest
        env:
          - name: CRON_SCHEDULE
            value: "0 * * * *"
          - name: TINI_SUBREAPER # tini won't be PID 1 due to shareProcessNamespace
            value: 
        volumeMounts:
        - mountPath: /etc/logrotate.conf
          name: configs-vol
          subPath: logrotate.conf
          readOnly: true
        - mountPath: /logs/
          name: logs-vol
      volumes:
      - name: logs-vol
        persistentVolumeClaim:
            claimName: logs
      - name: configs-vol
        configMap:
          name: configs

Customization

Option Default Description
CRON_SCHEDULE 0 * * * * Cron schedule for logrotate command

See Also

About

Image for sidecar containers that do log rotation

https://hub.docker.com/r/skymatic/logrotate

License:MIT License


Languages

Language:Makefile 39.2%Language:Dockerfile 34.2%Language:Shell 26.6%