7

Traefik's Getting Started guid is difficult to follow in any step by step fashion. It has the following problems:

  1. Getting Started suggests running traefik as a command, but no commands can be run on the traefik image and you must instead use traefik:alpine, even to shell into the container with docker exec -it ....
  2. Getting Started makes hardly any mention of a traefik.toml file.
  3. #1 makes a new reader confused as to weather traefik is intended to be run as a container that automatically updates per newly deployed containers like jwilder's nginx proxy or if it's intended to be run on a docker host.

Their original docker-compose.yml file looks like this:

version: '3' 

services:
  reverse-proxy:
    image: traefik # The official Traefik docker image
    command: --api --docker #--consul --consul.endpoint=127.0.0.1:8500 # Enables the web UI and tells Traefik to listen to docker
    ports:
      - "80:80"     # The HTTP port
      - "8080:8080" # The Web UI (enabled by --api)
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock # So that Traefik can listen to the Docker events
  whoami:
    image: containous/whoami # A container that exposes an API to show its IP address
    labels:
      - "traefik.frontend.rule=Host:whoami.docker.localhost"

Then you can run it with:

docker-compose up -d reverse-proxy

This is fine and you can add new services here and specify new labels like the one above, i.e. traefik.frontend.rule=Host:whoami-other.docker.localhost.

You can test this with curl, specifying the host heading like so:

curl -H Host:whoami.docker.localhost http://127.0.0.1

Issue 1)

Line 5 must be changed to use the image traefik:alpine.

    image: traefik:alpine # The official Traefik docker image

You can now actually docker exec this container. You can only use sh (not /bin/bash) on the alpine image. We can now do the following:

docker exec -it traefik_reverse-proxy_1 sh
docker exec -it traefik_reverse-proxy_1 traefik --help

Issue 2)

From the default docker-compose.yml, there is no mention of a traefik.toml file. Even if I docker-compose up -d [some_new_service] and can reach those services, shelling into the container has no traefik.toml file. It's nowhere in the container, despite that per the bottom of Basics, it says looks for it default locations such as /etc/traefik/ and $HOME/.traefik/ and . or the working directory. Is this referring to the host or the container? In the container I run grep find and only see the binary:

/ # find / | grep traefik
/usr/local/bin/traefik

Is traefik storing my services configuration in memory?

The next logical page in the documentation (Basics), immediately starts detailing configuration of the traefik.toml, but I have to such file to experiment with.

I had to to back to Getting Started read at the bottom of that page to find that using a static traefik.toml file must be specified in a volume when they suggest using their official image and running like this:

docker run -d -p 8080:8080 -p 80:80 -v $PWD/traefik.toml:/etc/traefik/traefik.toml traefik

So with this, I change the volumes section in the original docker-compose.yml under the service reverse-proxy to use something similar:

volumes:
  - /var/run/docker.sock:/var/run/docker.sock # So that Traefik can listen to the Docker events
  - $PWD/traefik.toml:/etc/traefik/traefik.toml

Even with this, I don't have a base traefik.toml file to even use (there isn't even one in the examples folder of their GitHub). I had to go find one, but wasn't even sure how it would apply to the existing configuration of services I had running (i.e. whoami and/or whoami-other). Finally, running find / | grep traefik on the container shows the same traefik.toml file in /etc/traefik/traefik.toml, but it has no mention of the services (which I can still reach with curl -H Host:whoami.docker.localhost http://127.0.0.1 from my docker host). Where is the configuration then?

Alexander Kleinhans
  • 5,950
  • 10
  • 55
  • 111
  • Rather than spite you anger, just read the doc... Sample file is right there : https://raw.githubusercontent.com/containous/traefik/v1.7/traefik.sample.toml referenced in the getting started just before the docker command you wrote. – Noki Aug 09 '19 at 21:41
  • 2
    @Noki I think this is traefik 1.7 ; PO using traefik 2.x – Semih Kekül Jan 22 '20 at 08:41
  • could you paste your toml file here, I can not access it somehow. – Semih Kekül Jan 22 '20 at 08:43
  • 1
    @SemihKekül, PO, is traefik < to 2.x because of the frontends labels used in his docker-compose file – Noki Jan 22 '20 at 09:59
  • @Noki I think you are right, sorry about that, but does not the line: image: traefik means getting the latest image which is 2.x . If that is the case the configuration of PO may be totaly wrong. – Semih Kekül Jan 22 '20 at 10:17
  • didn't see it this way but you're right too ! There is probably, a misconfiguration issue. Maybe the 24th of July there traefik v2 wasn't released yet, didn't checked – Noki Jan 22 '20 at 10:33
  • It's been a while but the only way I was able to get this working was to interact with docker using the Python API. toml configurations were being completely ignored. – Alexander Kleinhans Jan 24 '20 at 00:51
  • @Displayname could you share how exactly you got it working? – thisismydesign Apr 12 '20 at 23:18

1 Answers1

0

It is here https://raw.githubusercontent.com/containous/traefik/v2.0/traefik.sample.toml Somehow the traefik documents is confusing for newbie (I am).