How to forward request IP to service in Traefik v2?

How to forward the user's real IP to a service?

I am using Traefik v2 in Docker swarm.
Currently I get only an IP starting with 10.x.x.x.



You have to publish the port in host mode :


version: "3.6"


    image: "traefik:v2.0.0"

      - target: 80
        published: 80
        protocol: tcp
        mode: host
      - target: 443
        published: 443
        protocol: tcp
        mode: host

Would like to add, that this question crops up every now and then. Basically Traefik cannot add Real IP if it does not know it. And depending on docker configuration, sometimes you get only packets with internal source IP from docker. Those concerns really should be addressed in the docker community since they have little to do with traefik. That is not to say, that it's in any shape of form "bad" to answer them here - on the opposite, it's just that the topic is expansive (swarm vs plain, linux vs windows all have their own docker networking quircks), and if it is not addressed here, it would be no surprise.

Thank you both of you. For me, adding host mode solves the issue.

Thank you guys, the solution listed above also worked for me.