Some help with defaultRule please

I am not familiar enough with the Go formatting to get it to work but I would like a defaultRule in my traefik.yml that points to <appname>

The closest I have gotten is with this line:

defaultRule: "Host(\`{{ .Name }}\`)"

but that makes the rule the app name x2 and then the domain (ex: I guess because the compose is in a folder named librespeed that is starting a container named librespeed?

Looking at docker inspect librespeed I see that the value for "com.docker.compose.service" seems to consistently have just the app name ("librespeed") and what I want to fill in the for the subdomain portion of the default web address rule but I don't know how to pull it.

Someone gave me the following example but the syntax is not correct somehow and my other rules all crap out if I put it in:

`defaultRule: "Host(`{{ .Name }}.{{ index .Labels\"com.docker.compose.service\"}}\`)"

It seems like that line has too many entries but again I am not familiar with the formatting required here and there isn't much help in the docs. This is the example given accompanied by a reference to learn Go formatting:

 `defaultRule: "Host(`{{ .Name }}.{{ index .Labels \"customLabel\"}}`)"

Would someone be able to tell me how to properly format this line to get the desired result?

Well I figured out how to do it if anyone stumbles across this later:

defaultRule: "Host(`{{ index .Labels \"com.docker.compose.service\"}}`)"
1 Like