diff --git a/docker.go b/docker.go
index 5c73586c8..aefe0efdb 100644
--- a/docker.go
+++ b/docker.go
@@ -22,40 +22,6 @@ type DockerProvider struct {
Domain string
}
-var DockerFuncMap = template.FuncMap{
- "getBackend": func(container docker.Container) string {
- for key, value := range container.Config.Labels {
- if key == "traefik.backend" {
- return value
- }
- }
- return getHost(container)
- },
- "getPort": func(container docker.Container) string {
- for key, value := range container.Config.Labels {
- if key == "traefik.port" {
- return value
- }
- }
- for key := range container.NetworkSettings.Ports {
- return key.Port()
- }
- return ""
- },
- "getWeight": func(container docker.Container) string {
- for key, value := range container.Config.Labels {
- if key == "traefik.weight" {
- return value
- }
- }
- return "0"
- },
- "replace": func(s1 string, s2 string, s3 string) string {
- return strings.Replace(s3, s1, s2, -1)
- },
- "getHost": getHost,
-}
-
func (provider *DockerProvider) Provide(configurationChan chan<- configMessage) error {
if dockerClient, err := docker.NewClient(provider.Endpoint); err != nil {
log.Errorf("Failed to create a client for docker, error: %s", err)
@@ -105,6 +71,47 @@ func (provider *DockerProvider) Provide(configurationChan chan<- configMessage)
}
func (provider *DockerProvider) loadDockerConfig(dockerClient *docker.Client) *Configuration {
+ var DockerFuncMap = template.FuncMap{
+ "getBackend": func(container docker.Container) string {
+ for key, value := range container.Config.Labels {
+ if key == "traefik.backend" {
+ return value
+ }
+ }
+ return getHost(container)
+ },
+ "getPort": func(container docker.Container) string {
+ for key, value := range container.Config.Labels {
+ if key == "traefik.port" {
+ return value
+ }
+ }
+ for key := range container.NetworkSettings.Ports {
+ return key.Port()
+ }
+ return ""
+ },
+ "getWeight": func(container docker.Container) string {
+ for key, value := range container.Config.Labels {
+ if key == "traefik.weight" {
+ return value
+ }
+ }
+ return "0"
+ },
+ "getDomain": func(container docker.Container) string {
+ for key, value := range container.Config.Labels {
+ if key == "traefik.domain" {
+ return value
+ }
+ }
+ return provider.Domain
+ },
+ "replace": func(s1 string, s2 string, s3 string) string {
+ return strings.Replace(s3, s1, s2, -1)
+ },
+ "getHost": getHost,
+ }
configuration := new(Configuration)
containerList, _ := dockerClient.ListContainers(docker.ListContainersOptions{})
containersInspected := []docker.Container{}
diff --git a/docs/index.md b/docs/index.md
index d6d6fa407..05a2bf775 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -402,6 +402,7 @@ Labels can be used on containers to override default behaviour:
* `traefik.weight=10`: assign this weight to the container
* `traefik.enable=false`: disable this container in Træfɪk
* `traefik.host=bar`: override the default routing from {containerName}.{domain} to bar.{domain}
+* `traefik.domain=traefik.localhost`: override the default domain
## Marathon backend
@@ -461,6 +462,7 @@ Labels can be used on containers to override default behaviour:
* `traefik.enable=false`: disable this application in Træfɪk
* `traefik.host=bar`: override the default routing from {appName}.{domain} to bar.{domain}
* `traefik.prefixes=pf1,pf2`: use PathPrefix(es) instead of hostname for routing, use filename="providerTemplates/marathon-prefix.tmpl" with this option
+* `traefik.domain=traefik.localhost`: override the default domain
## Consul backend
diff --git a/marathon.go b/marathon.go
index 89d236f74..46b197007 100644
--- a/marathon.go
+++ b/marathon.go
@@ -21,42 +21,6 @@ type MarathonProvider struct {
NetworkInterface string
}
-var MarathonFuncMap = template.FuncMap{
- "getPort": func(task marathon.Task) string {
- for _, port := range task.Ports {
- return strconv.Itoa(port)
- }
- return ""
- },
- "getHost": func(application marathon.Application) string {
- for key, value := range application.Labels {
- if key == "traefik.host" {
- return value
- }
- }
- return strings.Replace(application.ID, "/", "", 1)
- },
- "getWeight": func(application marathon.Application) string {
- for key, value := range application.Labels {
- if key == "traefik.weight" {
- return value
- }
- }
- return "0"
- },
- "getPrefixes": func(application marathon.Application) ([]string, error) {
- for key, value := range application.Labels {
- if key == "traefik.prefixes" {
- return strings.Split(value, ","), nil
- }
- }
- return []string{}, nil
- },
- "replace": func(s1 string, s2 string, s3 string) string {
- return strings.Replace(s3, s1, s2, -1)
- },
-}
-
func (provider *MarathonProvider) Provide(configurationChan chan<- configMessage) error {
config := marathon.NewDefaultConfig()
config.URL = provider.Endpoint
@@ -91,6 +55,49 @@ func (provider *MarathonProvider) Provide(configurationChan chan<- configMessage
}
func (provider *MarathonProvider) loadMarathonConfig() *Configuration {
+ var MarathonFuncMap = template.FuncMap{
+ "getPort": func(task marathon.Task) string {
+ for _, port := range task.Ports {
+ return strconv.Itoa(port)
+ }
+ return ""
+ },
+ "getHost": func(application marathon.Application) string {
+ for key, value := range application.Labels {
+ if key == "traefik.host" {
+ return value
+ }
+ }
+ return strings.Replace(application.ID, "/", "", 1)
+ },
+ "getWeight": func(application marathon.Application) string {
+ for key, value := range application.Labels {
+ if key == "traefik.weight" {
+ return value
+ }
+ }
+ return "0"
+ },
+ "getDomain": func(application marathon.Application) string {
+ for key, value := range application.Labels {
+ if key == "traefik.domain" {
+ return value
+ }
+ }
+ return provider.Domain
+ },
+ "getPrefixes": func(application marathon.Application) ([]string, error) {
+ for key, value := range application.Labels {
+ if key == "traefik.prefixes" {
+ return strings.Split(value, ","), nil
+ }
+ }
+ return []string{}, nil
+ },
+ "replace": func(s1 string, s2 string, s3 string) string {
+ return strings.Replace(s3, s1, s2, -1)
+ },
+ }
configuration := new(Configuration)
applications, err := provider.marathonClient.Applications(nil)
diff --git a/providerTemplates/docker.tmpl b/providerTemplates/docker.tmpl
index 99c439107..9dfd6eac4 100644
--- a/providerTemplates/docker.tmpl
+++ b/providerTemplates/docker.tmpl
@@ -10,5 +10,5 @@
backend = "backend-{{getBackend $container}}"
[frontends.frontend-{{$host}}.routes.route-host-{{$host}}]
rule = "Host"
- value = "{{$host}}.{{$.Domain}}"
+ value = "{{$host}}.{{getDomain $container}}"
{{end}}
\ No newline at end of file
diff --git a/providerTemplates/marathon-prefix.tmpl b/providerTemplates/marathon-prefix.tmpl
index f30208c98..1a331626a 100644
--- a/providerTemplates/marathon-prefix.tmpl
+++ b/providerTemplates/marathon-prefix.tmpl
@@ -22,6 +22,6 @@
backend = "backend{{.ID | replace "/" "-"}}"
[frontends.frontend-{{getHost $app | replace "/" "-"}}.routes.route-host-{{getHost $app | replace "/" "-"}}]
rule = "Host"
- value = "{{getHost $app | replace "/" "-"}}.{{$.Domain}}"
+ value = "{{getHost $app | replace "/" "-"}}.{{getDomain .}}"
{{end}}
{{end}}
diff --git a/providerTemplates/marathon.tmpl b/providerTemplates/marathon.tmpl
index 895d494dc..10f1fa249 100644
--- a/providerTemplates/marathon.tmpl
+++ b/providerTemplates/marathon.tmpl
@@ -15,5 +15,5 @@
backend = "backend{{.ID | replace "/" "-"}}"
[frontends.frontend-{{getHost . | replace "/" "-"}}.routes.route-host-{{getHost . | replace "/" "-"}}]
rule = "Host"
- value = "{{getHost . | replace "/" "-"}}.{{$.Domain}}"
+ value = "{{getHost . | replace "/" "-"}}.{{getDomain .}}"
{{end}}
\ No newline at end of file