r/Traefik•
Cytoo

Trying to figuring traefik entrypoints configuration

I am new to docker and traefik, and have been trying to set up a basic environment all day long but I've been strugling to achieve what I really want.

I am running an archlinux server, with:

$docker-compose -v                                                                                  
docker-compose version 1.25.5, build unknown
$docker -v
Docker version 19.03.8-ce, build afacb8b7f0

and using docker image traefik:v2.2.

So basically, I would like to have a setup with 3 entrypoints:

  • :80 that redirects to https
  • :443 https
  • :8080 Only for the api/dashboard

I am just going to ignore the http to https redirection for now and focus on this :8080 entrypoint. Using this docker-compose file:

version: '3' 

services:
  reverse-proxy:
    # The official v2 Traefik docker image
    image: traefik:v2.2
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
    volumes:
      # So that Traefik can listen to the Docker events
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - "./traefik/traefik.toml:/traefik.toml"
      - "./traefik/acme.json:/acme.json"
    networks:
      - web
    # attaching labels for dynamic conf
    labels:
      - "traefik.http.routers.api.rule=Host(`api.hostname.me`)"
      - "traefik.http.routers.api.entrypoints=dashboard"
      - "traefik.http.routers.api.service=api@internal"
      - "traefik.http.routers.api.middlewares=auth"
      - "traefik.http.middlewares.auth.basicauth.users=<pass>"

  whoami:
    image: containous/whoami
    labels:
      - "traefik.http.routers.whoami.rule=Host(`monitor.hostname.me`)"

networks:
  web:
    driver: bridge

and this static traefik configuration file

[global]
    sendAnonymousUsage = false

[entryPoints]
    [entryPoints.web]
        address = ":80"
        [entryPoints.web.http]
            [entryPoints.web.http.redirections]
                [entryPoints.web.http.redirections.entryPoint]
                    to = "websecure"
                    scheme = "https"

    [entryPoints.websecure]
        address = ":443"
        [entryPoints.websecure.http.tls]
            certResolver = "leresolver"  

    [entryPoints.dashboard]
        address = ":8080"
[providers]
    [providers.docker]
        endpoint = "unix:///var/run/docker.sock"   
        watch = true
        network = "web"

[api]
    dashboard = true

Now, what I can notice is that I get the dashboard when accessing api.hostname.me:8080 (this is not over https yet, but I'll fix this late). I do not get it when trying api.hostname.me:80 (and it redirects over https, so this works fine).

Now, testing the other router for the whoami docker container, I notice I get it either from :80 (with no redirection), :443 and :8080.

Apparently, if you don't specify specific entryPoints for a router, it will accept from all the entry point declared. I do not really find this to be a correct behavior, as one can easily forget to restrict the pool of entrypoints to its likeliness. Is there a way to have no default entrypoints ?

Also, considering the redirection does not seem to be effective in the second case, does anyone have an idea ?

It appears that sometimes docker-compose restart is just not enough.

Posted Apr 12, 2020, 8:27 PM UTC · edited

25
vll_dk•

If you don’t define entryPoints, how would you expect anything to be routed to your service?

1
CytooOP•

Exactly, I would expect nothing to be routed instead of everything, which seems to be the default behaviour.

1
vll_dk•

It is - if you don’t want anything routed you wouldn’t specify the entryPoint? I’m not sure I understand the problem, I think the default behaviour is as it should be

Edit: is this issue related?

Edit 2: it is an option in 1.7: defaultEntryPoints

1
CytooOP•

Yes, but it was refactored in v2.

In this version, the default entrypoints are all the entrypoints

1
vll_dk•

Why do you ask then?

You can check for open issues related to this here if you want and open one if there isn’t one already

1