How to add current hostname in customresponseheaders (for use with Docker Swarm)?

I would like to use Traefik with Docker Swarm, every proxy node gets a Traefik instance with the same common configuration.

To be able to see if all Traefik reverse proxies are available behind the load balancer, I would like every Traefik instance to add their hostname in the response header.

I found the Traefik configuration for headers, but it seems there is no way to access local settings like $HOSTNAME.

So something like this is not possible?

  - "traefik.http.middlewares.testHeader.headers.customresponseheaders.proxy-host=$HOSTNAME"

That is not a traefik issue rather a docker one. See this for why and workaround.

Thanks for your reply.

My understanding is that the link shows how to include ENV when executing docker stack deploy command. That way I can include the management server $HOSTNAME in the docker stack deploy file, but it will be the same on every node the Traefik instance is started.

I am looking for a way the Traefik instance can read it's local ENV and place the local $HOSTNAME value in the customresponseheaders header.

Yes you're correct

I don't think this is possible. Running multiple traefik will be of limited benefit, particularly if you want to use LetsEncrypt.

I have a managed Cloud Load Balancer in front, but it does not support domain-based routing.

The Cloud Load Balancer forwards round-robin plain TCP/IP (80/443) to 3 Traefik instances (for failover).

Those are in a Docker Swarm and do the routing to the registered services on separate nodes.

So if I do multiple requests via LB, it would be interested to see which Traefik instances are involved.

Maybe I just setup the Traefik instances manually, they probably don't need to be scaled up and down.

PS: Letsencrypt is great, but for serious paid business I prefer paid certificates.

Really in swarm though you only need one. As the swarm routing mesh will take care of getting it to traefik.

For a more robust solution TraefikEE is the way to go.

While testing with whoami I found that traefik is automatically including its container hostname in the X-Forwarded-Server header.

And Docker Swarm will set a containers hostname to the nodes hostname when using


This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.