diff --git a/docs/content/providers/docker.md b/docs/content/providers/docker.md index 6b30ae64f..64924b39b 100644 --- a/docs/content/providers/docker.md +++ b/docs/content/providers/docker.md @@ -440,10 +440,11 @@ _Optional, Default=```Host(`{{ normalize .Name }}`)```_ The `defaultRule` option defines what routing rule to apply to a container if no rule is defined by a label. -It must be a valid [Go template](https://pkg.go.dev/text/template/), and can use -[sprig template functions](https://masterminds.github.io/sprig/). -The container service name can be accessed with the `Name` identifier, -and the template has access to all the labels defined on this container. +It must be a valid [Go template](https://pkg.go.dev/text/template/), +and can use [sprig template functions](https://masterminds.github.io/sprig/). +The container name can be accessed with the `ContainerName` identifier. +The service name can be accessed with the `Name` identifier. +The template has access to all the labels defined on this container with the `Labels` identifier. ```yaml tab="File (YAML)" providers: diff --git a/pkg/provider/docker/config.go b/pkg/provider/docker/config.go index f006d7b57..75110d095 100644 --- a/pkg/provider/docker/config.go +++ b/pkg/provider/docker/config.go @@ -74,11 +74,13 @@ func (p *Provider) buildConfiguration(ctx context.Context, containersInspected [ serviceName := getServiceName(container) model := struct { - Name string - Labels map[string]string + Name string + ContainerName string + Labels map[string]string }{ - Name: serviceName, - Labels: container.Labels, + Name: serviceName, + ContainerName: strings.TrimPrefix(container.Name, "/"), + Labels: container.Labels, } provider.BuildRouterConfiguration(ctx, confFromLabel.HTTP, serviceName, p.defaultRuleTpl, model)