Template to get container name includes leading slash
bjeanes opened this issue · 2 comments
The README gives the following example to dynamically get the container name:
caddy.respond: /info "{{index .Names 0}}"
↓
respond /info "mycontainer"
Despite the example, it actually appears to correspond to respond /info "/mycontainer"
I found I had to use the following template string to get the container name, but I am not sure how one would do this outside of docker compose:
{{ index .Labels "com.docker.compose.service" }}
Yeah. All container names have a leading slash in docker. I didn't know that until now. That example in the readme is wrong.
You can try to use some go template function to trim the leading slash. We could even add back sprig https://github.com/Masterminds/sprig to have a lot of functions available.
You can try to use some go template function to trim the leading slash.
I tried to find a function to do this, but I am not very familiar with Go and so couldn't confirm that there was a builtin to do this (but did also find sprig).
In any case, within docker compose, as I am, I have the workaround I posted above.