3

I'm trying to logrotate access logs with traefik docker on the host. When logrotate run it create a new log file, great, but it always to zero like if the docker volume was not remount. On traefik docker the access log still continue to grow. What is the trick to logrotate my access log ? thx

my /etc/logrotate.d/traefik

/var/www/traefik_access.log {
  size 10K
  rotate 30
  missingok
  notifempty
  compress
  dateext
  dateformat .%Y-%m-%d
  create 0644 www-data www-data
  postrotate
    docker kill --signal="USR1" traefik
  endscript
}

my docker-compose.yml :

version: '3'

services:
  traefik:
    image: traefik:latest
    container_name: traefik
    restart: always
    ports:
    - 80:80
    - 443:443
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    - ./traefik.toml:/traefik.toml
    - ./acme.json:/acme.json
    - ./traefik_access.log:/access.log
    networks:
    - web

my files

-rw-r--r--  1 www-data www-data  1818 août   7 11:30 traefik_access.log.2019-08-07.gz
-rw-r--r--  1 www-data www-data     0 août   7 11:30 traefik_access.log
jrweb247
  • 95
  • 1
  • 8

1 Answers1

4

I faced the same issue with 'traefik:chevrotin'. I found a solution at this How to enable logrotation for traefik? thread thanks to @anastymous comment.

For the USR1 signal to be correctly applied, in the docker-compose.yml you need to bind a log directory where logs are located instead of binding each log files.

Successful logrotation at signal USR1 received:

OK docker-compose.yml

services:

  traefik:
    image: "traefik:chevrotin"
    container_name: "traefik"
    restart: "unless-stopped"
    command:
      - "--log.level=DEBUG"
      - "--log.filePath=/logs/traefik.log"
      - "--accessLog.filePath=/logs/access.log"
    volumes:
      - "/var/log/traefik:/logs" #make sure to touch log files before starting container

Failed logrotation at signal USR1 received:

NOK docker-compose.yml

services:

  traefik:
    image: "traefik:chevrotin"
    container_name: "traefik"
    restart: "unless-stopped"
    command:
      - "--log.level=DEBUG"
      - "--log.filePath=/logs/traefik.log"
      - "--accessLog.filePath=/logs/access.log"
    volumes:
      - "/var/log/traefik.log:/logs/traefik.log"
      - "/var/log/traefik-access.log:/logs/acccess.log"

Hope it can helps !

  • I was just looking for activating log rotation for my traefik container (docker) and stumbled upon this. Thanks for sharing your insight! – RedPanda May 08 '21 at 17:57