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

URL Variables as Docker Labels? #98

Closed
polds opened this issue Nov 9, 2015 · 5 comments
Closed

URL Variables as Docker Labels? #98

polds opened this issue Nov 9, 2015 · 5 comments

Comments

@polds
Copy link

polds commented Nov 9, 2015

Wondering if it's possible to do URL Variables as part of a Docker label like so:

docker run ... \
  --label traefik.frontend.rule=Host \
  --label traefik.frontend.value={subdomain:[a-z]+}.example.com \
  ...
@polds
Copy link
Author

polds commented Nov 9, 2015

Looked into it a little more when trying to pass that as a Docker label the toml package throws the following error:

Error creating docker configuration Near line 8, key 'frontends': Near line 8: Table names cannot contain '[' or ']'.

Looks like because the entire frontend name is being used as per docker.tmpl it's attempting also inject the regex into the table name.

Please see the referenced commit for my fixes. If you think these are inline I can make a PR. I'm not exactly sure what to return with if the parsing failed. Right now it returns the original string (Don't like this)

@emilevauge
Copy link
Member

Hi @polds, thank you for reporting. This is an issue. We have to find a smart way to do that. I'm not sure to understand what does:

"makeParsedUrl": func(s1 string) string {
            if u, err := url.Parse(s1); err == nil {
                return u.String()
            }
            return s1
        },

Could you explain a little bit ?

@polds
Copy link
Author

polds commented Nov 12, 2015

@emilevauge it converts the string to their html entities counterparts. Going in the string is {subdomain: [a-z]+}.example.com and coming back it is converted to an ugly, but safe: %7Bsubdomain:%20%5Ba-z%5D+%7D.example.com but still parsed correctly by Traefik.

My biggest concern is if the url.Parse() fails I have it returning the same string which would inevitably cause issues if url.Parse() can't handle it. I'm wondering if just returning the string "error" would be better.

Edit: The TOML parser was only specifically complaining about the [ ] so perhaps instead of introducing a new template function we use the already available replace function and do something like so:

{{$frontend | replace "[" "" | replace "]" ""}}

@emilevauge
Copy link
Member

@polds, OK I get it. I definitely prefer the second solution to reuse the replace template function. Would you make a PR on that point?

@emilevauge emilevauge added the bug label Nov 12, 2015
@emilevauge
Copy link
Member

Or even better, should be added directly here: https://github.com/emilevauge/traefik/blob/master/provider/docker.go#L209

@emilevauge emilevauge modified the milestone: 1.0 Feb 27, 2016
@traefik traefik locked and limited conversation to collaborators Sep 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants