Traefik not writing log files

Hi guys!

I have a working docker-compose that uses traefik alpine. I am using debian 9 as the main distro.

The problem is that its not writing any logfiles.

My docker-compose.yml looks like this

version: "3"

services:
  traefik:
    container_name: traefik
    image: traefik:alpine
    networks:
      - server
    ports:
      - 80:80
      - 443:443
    volumes:
      - /opt/traefik/traefik.toml:/traefik.toml:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /opt/traefik/acme.json:/acme.json
    labels:
      - traefik.enable=true
      - traefik.port=8080
      - traefik.frontend.rule=Host:top.example.xyz
    command:
      - --accessLog=true
      - --logLevel=INFO
      - --accessLog.filePath="/opt/traefik/access.log"
      - --traefikLog.filePath="/opt/traefik/traefik.log"
      - --traefikLog.format="json"
      - --accessLog.format="json"

networks:
  server:
    external: true

And traefik.toml

logLevel = "INFO"
checkNewVersion = true

defaultEntryPoints = ["http", "https"]

[entryPoints]
  [entryPoints.dashboard]
    address = ":8080"
    [entryPoints.dashboard.auth]
      [entryPoints.dashboard.auth.basic]
        users = ["test:$apr1$k56KsfIu$7RI1JNkmwXpjqyaLPYuIA."]
  [entryPoints.http]
    address = ":80"
      [entryPoints.http.redirect]
        entryPoint = "https"
  [entryPoints.https]
    address = ":443"
      [entryPoints.https.tls]

[api]
entrypoint="dashboard"
dashboard = true

[retry]

[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "example.xyz"
exposedByDefault = false
watch = true

[acme]
email = "example@example.com"
storage = "acme.json"
entryPoint = "https"
onHostRule = true
  [acme.httpChallenge]
entryPoint = "http"

I am using traefik:alpine and the version is v1.7.12 and I changed my real domain to example.

I've tried different locations for access.log and traefik.log but nothing seems to be created. My purpose is to get it create logfiles so I can implement it with fail2ban.

Hi @thepenguinthatwants,where are looking at the log files? It looks like that you did not mount the directory /opt/traefik from Traefik's container, so if you are looking on the host machine, this directory won't be visible as docker container have isolated filesystems.

Also, there are a few configuration hiccups that should be fixed to avoid any side effects:

  • Mixing CLI flags and TOML for the "static configuration" is discouraged (it won't even work with Traefik v2.0). As you are using a traefik.toml, I would recommend you to:
    • Remove the section command: for the service traefik in your docker-compose.yml
    • Add the following TOML snippet to traefik.toml (transcription of the CLI flags into TOML as described in the reference documentation: <>)
[traefikLog]
  filePath = "/opt/traefik/traefik.log"
  format   = "json"

[accessLog]
  filePath = "/opt/traefik/access.log"
  format = "json"

I used your snippet to reproduce and traefik writes the logs in this case for sure:

$ docker-compose up -d
$ docker-compose exec traefik ls -l /opt/traefik
total 8
-rw-r--r--    1 root     root          2195 Jul 31 09:57 access.log
-rw-r--r--    1 root     root          2868 Jul 31 09:57 traefik.log

I was looking the log files at /opt/traefik of my server host. You are right I havent mounted the one that should contains logs.. So If I am not wrong then traefik docker image location for logs is /opt/traefik.

Thanks for pointing out this. I found it kinda hard to understand those TOML so I decided mixing those flags. Now I understand where the problem lies.

I mounted the docker socker read-only because I thought it was for increasing security.

"AFAIK :ro on a unix domain socket just prevent you to rename/remove it" Damns

Thanks for the feedback @thepenguinthatwants! Have fun with Traefik :wink: