Traefik Label Tips
This article details some useful Traefik labels to help you get the most of out of some of the more popular Docker Images out there, that we use. It's a follow on from our "OMV, Portainer, Traefik and LetsEncrypt" article - but if you can apply a label to a Docker container, and have Traefik, you can use this article!
Note: This article assumes you have Traefik installed and your containers accessible via URL via Traefik.
Table Of Contents
FreePBX (admin and UCP redirection)
We use tiredofit/freepbx:latest for our FreePBX VoIP setup - it's a great image, with active support.
FreePBX has two main URLs - one for administration and one for users (the User Control Panel or UCP) - typically accessed via http://yourfreepbxhost/admin or http://yourfreepbxhost/ucp - but if you've stuck FreePBX behind Traefik (as we have) then you may want to split out a subdomain for each, i.e.:
This snippet assumes you have two dedicated URLs, one per GUI - like the above.
Add the following labels to your FreePBX container:
traefik.http.middlewares.mw_freepbxadmin.addprefix.prefix with the value /admin
traefik.http.middlewares.mw_freepbxucp.addprefix.prefix with the value /ucp
traefik.http.middlewares.mw_ucpredirect.redirectregex.regex with the value ^https://freepbx.yoursubdomain.yourdomain.com/ucp
traefik.http.middlewares.mw_cdrredirect.redirectregex.regex with the value ^https://freepbx.yoursubdomain.yourdomain.com/admin/config.php
As you'll have had to define two Traefik routers, one for admin and one for UCP, Now add (or update) your middleware label for your ZoneMinder router:
traefik.http.routers.freepbxadmin.middlewares to include mw_ucpredirect,mw_cdrredirect,mw_freepbxadmin
traefik.http.routers.freepbxucp.middlewares to include mw_freepbxucp
The admin GUI has links to the UCP, so you need to include the UCP redirect before the admin router one (to catch it before any prepending) - but the UCP router will only need the one for itself.
pihole (admin shortcut)
We covered this in our main article, but just in case you missed it, or didn't follow it but want the shortcut - here we go.
Simply add this label (name in bold) to your pihole container
traefik.http.middlewares.mw_piholeadmin.addprefix.prefix with the value /admin
Then, add (or update) the middleware label for your pihole router:
traefik.http.routers.pihole.middlewares to include mw_piholeadmin
Any access to your pihole will now automatically redirect you to the admin page.
Traefik (Network error suppression)
One of our readers (Andreas Herbst) queried some errors that traefik was displaying after following our guide.
The errors look similar to this:
The error is caused by Traefik expecting containers to be on the "bridge" network, and in some cases they are on the "host" or macvlan networks ("DockerNetwork", if you were following our guide).
These errors are harmless, but can be annoying if you have a lot of containers. To get around this, add the following label to your container
traefik.docker.network with the value xxxx
...where xxxxis the name of the network your container uses, i.e. host, DockerNetwork etc - and then restart Traefik
ZoneMinder (URL shortener and CGI hack)
We use quantumobject/docker-zoneminder:latest for our ZoneMinder container, but like all ZoneMinder containers, it was based on an original image running on (or behind) Apache, and all URLs start with /zm - so to avoid typing that in when it's on a localised URL, we can add the following middleware definitions
traefik.http.middlewares.mw_addzm.addprefix.prefix with the value /zm
traefik.http.middlewares.mw_zmcgi.replacepathregex.regex with the value /zm/
traefik.http.middlewares.mw_zmcgi.replacepathregex.replacement with the value /
Now add (or update) your middleware label for your ZoneMinder router:
traefik.http.routers.zoneminder.middlewares to include mw_zmcgi,mw_addzm
The above middlewares will prefix /zm onto any URL sent to that Traefik router (ZoneMinder) meaning you don't have to add /zm all the time. Additionally, and again because ZoneMinder is expecting to run on a native Apache host, any of it's /cgi-bin links would fail, as the prior middleware would change to the be /zm/cgi-bin - so the second pair of middleware instructions looks for anything coming in with /zm/ on the front and removes it - but leaves /zm (not /zm/) intact.
Note: The middleware addition must be in the order mw_zmcgi, mw_addzm - otherwise they will conflict - for the above reason.