Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template to get container name includes leading slash #648

Open
bjeanes opened this issue Jul 31, 2024 · 2 comments
Open

Template to get container name includes leading slash #648

bjeanes opened this issue Jul 31, 2024 · 2 comments

Comments

@bjeanes
Copy link

bjeanes commented Jul 31, 2024

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" }}
@lucaslorentz
Copy link
Owner

Yeah. All container names have a leading slash in docker. I didn't know that until now. That example in the readme is wrong.
Screenshot 2024-08-10 at 10 04 57

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.

@bjeanes
Copy link
Author

bjeanes commented Aug 12, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants