skip to Main Content

I’m a complete docker noob. Just installed docker and docker-compose as well as portainer following a tutorial.

Now I would like to set up traefik reverse proxy on portainer.

This is the traefik.yml file in /etc/traefik

  global:
  checkNewVersion: true
  sendAnonymousUsage: false  # true by default

# (Optional) Log information
# ---
# log:
#  level: ERROR  # DEBUG, INFO, WARNING, ERROR, CRITICAL
#   format: common  # common, json, logfmt
#   filePath: /var/log/traefik/traefik.log

# (Optional) Accesslog
# ---
# accesslog:
  # format: common  # common, json, logfmt
  # filePath: /var/log/traefik/access.log

# (Optional) Enable API and Dashboard
# ---
 api:
  dashboard: true  # true by default
  insecure: true  # Don't do this in production!

# Entry Points configuration
# ---
entryPoints:
  web:
    address: :80
    # (Optional) Redirect to HTTPS
    # ---
    # http:
    #   redirections:
    #     entryPoint:
    #       to: websecure
    #       scheme: https

  websecure:
    address: :443

# Certificates configuration
# ---
# TODO: Custmoize your Cert Resolvers and Domain settings
# 

This is the docker-compose file:

version: '3'

volumes:
  traefik-ssl-certs:
    driver: local

services:
  traefik:
    image: "traefik:v2.5"
    container_name: "traefik"
    ports:
      - "80:80"
      - "443:443"
      # (Optional) Expose Dashboard
      - "8080:8080"  # Don't do this in production!
    volumes:
      - /etc/traefik:/etc/traefik
      - traefik-ssl-certs:/ssl-certs
      - /var/run/docker.sock:/var/run/docker.sock:ro

But when I try to start the container I get this error:

2021/12/08 18:08:07 command traefik error: yaml: line 19: did not find expected key

I can get the container to run when I remove the whole "volumes" section under "services" from the docker-compose file, but I need it for my traefik set up. I have no clue what I did wrong as I am following a video tutorial for this 1:1

2

Answers


  1. I cannot recreate your exact error message, but I got an error when using your exact traefik.yml config file (as posted in the question) as the syntax is invalid (as pointed out in another answer).

    I reduced the compose file to the minimum:

    version: '3'
    
    services:
      traefik:
        image: "traefik:v2.5"
        container_name: "traefik"
        volumes:
           - 'c:temptraefiketctraefik.yml:/etc/traefik/traefik.yml'
    

    And mounted just the traefik.yml file into the container as you can see. The file is shown below with commented out lines removed:

      global:
      checkNewVersion: true
      sendAnonymousUsage: false  # true by default
    
     api:
      dashboard: true  # true by default
      insecure: true  # Don't do this in production!
    
    entryPoints:
      web:
        address: :80
    
      websecure:
        address: :443
    

    Running a docker-compose up on this gives the following error:

    c:Temptraefik>docker-compose up
    [+] Running 1/0
     - Container traefik  Created                                            0.0s
    Attaching to traefik
    traefik  | 2021/12/09 08:44:36 command traefik error: no valid configuration found in file: /etc/traefik/traefik.yml
    traefik exited with code 1
    

    When I fix the indentation in the traefik.yml file (and turn on DEBUG logging) I have this:

    global:
      checkNewVersion: true
      sendAnonymousUsage: false  # true by default
    
    api:
      dashboard: true  # true by default
      insecure: true  # Don't do this in production!
    
    entryPoints:
      web:
        address: :80
    
      websecure:
        address: :443
    
    log:
      level: DEBUG 
    

    and running docker-compose up again I now get this:

    c:Temptraefik>docker-compose up
    [+] Running 2/2
     - Network traefik_default  Created                                      0.2s
     - Container traefik        Created                                     29.5s
    Attaching to traefik
    traefik  | time="2021-12-09T08:49:30Z" level=info msg="Configuration loaded from file: /etc/traefik/traefik.yml"
    traefik  | time="2021-12-09T08:49:30Z" level=info msg="Traefik version 2.5.4 built on 2021-11-08T17:41:41Z"
    traefik  | time="2021-12-09T08:49:30Z" level=debug msg="Static configuration loaded {"global":{"checkNewVersion":true},"serversTransport":{"maxIdleConnsPerHost":200},"entryPoints":{"traefik":{"address":":8080","transport":{"lifeCycle":{"graceTimeOut":"10s"},"respondingTimeouts":{"idleTimeout":"3m0s"}},"forwardedHeaders":{},"http":{},"udp":{"timeout":"3s"}},"web":{"address":":80","transport":{"lifeCycle":{"graceTimeOut":"10s"},"respondingTimeouts":{"idleTimeout":"3m0s"}},"forwardedHeaders":{},"http":{},"udp":{"timeout":"3s"}},"websecure":{"address":":443","transport":{"lifeCycle":{"graceTimeOut":"10s"},"respondingTimeouts":{"idleTimeout":"3m0s"}},"forwardedHeaders":{},"http":{},"udp":{"timeout":"3s"}}},"providers":{"providersThrottleDuration":"2s"},"api":{"insecure":true,"dashboard":true},"log":{"level":"DEBUG","format":"common"},"pilot":{"dashboard":true}}"
    traefik  | time="2021-12-09T08:49:30Z" level=info msg="nStats collection is disabled.nHelp us improve Traefik by turning this feature on :)nMore details on: https://doc.traefik.io/traefik/contributing/data-collection/n"
    traefik  | time="2021-12-09T08:49:30Z" level=info msg="Starting provider aggregator.ProviderAggregator {}"
    ...
    ...
    

    So it can be seen that traefik starts up. This is not necessarily the same issue you have, but it shows how to approach troubleshooting it. Once you know your traefik configuration is good, you can add DEBUG logging and then try adding the other volumes and configuration so see if they are OK too.

    Login or Signup to reply.
  2. I think you should check your traefik.yml indentation. There are some keys at different levels and YAML is pretty sensible to this. I’m talking specially about:

    • global
    • checkNewVersion
    • sendAnonymousUsage
    • api

    Check the number of spaces before them.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search