Traefik v2 access.log don't created

Hello,
I want understand why my access.log file was not created.
All work but i don't have the access.log file.
This is my docker-compose file :

version: "3"

services:

  traefik:
    image: traefik:v2.0.6
    container_name: "traefik"
    restart: always
    ports:
      - "80:80"
      - "443:443"
    command:
      - --global.checkNewVersion=true
      - --global.sendAnonymousUsage=true
      - --entryPoints.web.address=:80
      - --entryPoints.websecure.address=:443
      - --log.level=DEBUG
      #- --log.filePath=/home/asterix/traefik.log
      #- --log.format=json
      - --accesslog=true
      - --accesslog.filepath=/home/asterix/access.log
      - --accesslog.bufferingsize=100
      - --accesslog.format=json
      - --api
      - --ping
      - --certificatesresolvers.myhttpchallenge.acme.httpchallenge=true
      - --certificatesresolvers.myhttpchallenge.acme.httpchallenge.entrypoint=web
      - --certificatesresolvers.myhttpchallenge.acme.email=myemail@domaine.com
      - --certificatesresolvers.myhttpchallenge.acme.storage=/letsencrypt/acme.json
      - --providers.docker.exposedByDefault=false
      # - --providers.docker.watch=true
      # - --providers.docker.swarmMode=true
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - "./letsencrypt:/letsencrypt"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.traefik_https.rule=Host(`xxx.domaine.com`)"
      - "traefik.http.routers.traefik_https.entrypoints=websecure"
      #- "traefik.http.routers.traefik_https.tls=true"
      #- "traefik.http.routers.traefik_https.tls.certResolver=letsencrypt"
      - "traefik.http.routers.traefik_https.tls.certresolver=myhttpchallenge"
      - "traefik.http.routers.traefik_https.service=api@internal"
      - "traefik.http.routers.traefik_https.middlewares=traefik-auth"
      # - "traefik.http.services.noop.loadbalancer.server.port=888"
      # required only for swarm
      - "traefik.http.middlewares.traefik-auth.basicauth.users=admin:$$apr1$$a6P97nso$$5eGredHgC8EuQpV0sh1Ge0"
      - "traefik.http.routers.http_traefik.rule=Host(`xxx.domaine.com`)"
      - "traefik.http.routers.http_traefik.entrypoints=web"
      - "traefik.http.routers.http_traefik.middlewares=https_redirect"
      - "traefik.http.middlewares.https_redirect.redirectscheme.scheme=https"
      - "traefik.http.middlewares.https_redirect.redirectscheme.permanent=true"

Hi,
Thanks for using Træfik.

Does your /home/asterix/access.log file exists ?
As I can see, you didn't mapped the log file volume to the container
See this to view how to do that (I used toml declaration but it works with commands instead) https://github.com/Darkweak/WorkshopContainous/blob/master/final/traefik

3 Likes

It's work now ! Thank's you so much @darkweak !

thanks for the solution, I faced the same issue but where is that documented that you have to mapped this path?
I assume, when the commands

--accesslog=true
--accesslog.filepath=/home/asterix/access.log

are added, traefik does that by himself.
By the way, my docker-compose.yml lists the commands without leading -,
so instead of

- --accesslog=true
- --accesslog.filepath=/home/asterix/access.log

I do

--accesslog=true
--accesslog.filepath=/home/asterix/access.log

Is there any important difference?

Hello @PackElend

I don't found in the documentation (https://docs.traefik.io/observability/logs/) where we must mapped the path for access.log.

For the difference between :

- --accesslog=true
- --accesslog.filepath=/home/asterix/access.log

I do

--accesslog=true
--accesslog.filepath=/home/asterix/access.log

I think it's not important.

I hope you have helped.
Asterix.

You do not have to map the path if you do not need to access directly from the host (that is you are happy to access it in the container context, e.g with docker exec).

If you do, I find this part of the docker documentation quite comprehensive:

As far as the command goes it's a difference between the list and string format as described here: https://docs.docker.com/compose/compose-file/#command

Yaml spec (See section "2.1. Collections" of version 1.2 for different ways to represent a list in yaml) and https://yaml-multiline.info/ are also useful in order to understand how yaml handles lists and strings.

It makes a difference when you want to insert comments between the commands, see linux - Use inline comments in docker-compose command - Stack Overflow.

Checking the content of a yaml file is easy thing using Online YAML Parser
So I figured out how it gets accepted by the parser:

  traefik-reverse-proxy:   
    # The official v2.0 Traefik docker image
    image: traefik:latest 
    #image: traefik:v2.0
    container_name: "traefik"       
    command:
    # to work with custom traefil configuration file you have to declare the local path and mount the location on the host, see volume section
    - --configFile=/etc/traefik/traefik-config.yaml
    # another comment
    - --next command #1
    - --and again
1 Like

thanks and see answer above :slight_smile:

I have figured today that traefik cannot write file in /opt/* and doesn't tell...

awesome thanks for this!

1 Like