Traefik works great. Setting it up may require some perseverance. In this post you find a number of hints on upgrading to Traefik v2.5 in a Docker Swarm environment. In the question about how to use the $ sign.
What are the rules for using $ signs and environment variables in the dynamic Traefik configuration in docker-compose files? What is the design behind this way of coding?
I haven't found a solid description on what to use in the docker-compose file for Traefik. Yes, Treafik documentation mentions a few times that we should take care of the $ sign.
As a 'spec by example' after scanning the internet, are these all valid? Are there better ways? => yes
- "traefik.http.routers.mycomp.rule=Host(`somwhere.uk`) && PathPrefix(`/comp/${STACK_NAME}}`)"
- "traefik.http.routers.mycomp.service=wiremock_${STACK_NAME}"
Basic authentication: so, doubling any $ sign => yes
- "traefik.http.middlewares.dashboard.basicauth.users=admin:$$2a$$13$$xoE7...HG"
Replacements: doubling any $ sign? => yes
- "traefik.http.middlewares.grafana.replacepathregex.regex=^/grafana/(.*)" with
- "traefik.http.middlewares.grafana.replacepathregex.replacement=/$$1"
Replacements with an environment variable. Just like this?
- "traefik.http.routers.dkkbeheerapp.middlewares=abc"
- "traefik.http.middlewares.abc.stripprefix.prefixes=/prefix/${STACK_NAME}"
Regexps:doubling any $ sign? => yes
- "traefik.http.routers.alertmanager.middlewares=abc,def"
- "traefik.http.middlewares.abc.redirectregex.regex=^(.*)/alertmanager$$"
- "traefik.http.middlewares.abc.redirectregex.replacement=$$1/alertmanager/"
- "traefik.http.middlewares.def.replacepathregex.regex=^/alertmanager/(.*)"
- "traefik.http.middlewares.def.replacepathregex.replacement=/alertmanager/$$1"
Finally I got all Traefik v1 config upgraded to v2.5.
The configs given in the question are all valid.
Maybe you value some conversion hints to Traefik v2.5 in a Docker Swarm:
- When you have different host names, back-quote each of them. So, Host( `a`, `b`).
- There is a conversion tool. Be aware that the standard global: {} gives errors. Use the clause only with at least one property, like checkNewVersion: false.
- In a set of different Docker Swarms and multiple nodes, you may have to listen to Docker events on a specific Docker EE managers port. Not the /var/run/docker.sock.
- In a Docker Swarm you may use service names like stack_container. I had to use these stack_container name as well as the name in the routers, not just 'container'.
- Don't forget to put the Traefik labels under the deploy section of your service (in a docker-compose.yml) file.
- When you get this message (failed ... InvalidArgument desc = only updates to Labels are allowed) then you should remove (or update via a version-suffix) your static traefik configuration file.
Enjoy Traefik v2.5+