Traefik 2 docker not showing client real ip

I have traefik running in docker (on a windows host). The problem I have is that the X-Real-IP header alawys shows the docker network gateway ip instead of the real client ip. I'm not sure what I'm doing wrong, I know traefik in host network mode should work, but then it would no longer find the docker services on it's own.

This is my docker compose file:

version: "3.7"

networks:
  t2_proxy:
    external:
      name: t2_proxy
  default:
    driver: bridge

services:
  traefik:
    # The official v2 Traefik docker image
    image: traefik/traefik:latest
    container_name: traefik
    restart: unless-stopped
    # Enables the web UI and tells Traefik to listen to docker
    command: # CLI arguments
      - --global.checkNewVersion=true
      - --global.sendAnonymousUsage=true
      - --entryPoints.https.address=:443
      - --api=true
      - --api.insecure=true
      - --api.dashboard=true
      - --log=true
      - --log.level=INFO # (Default: error) DEBUG, INFO, WARN, ERROR, FATAL, PANIC
      - --accessLog=true
      - --accessLog.filePath=/traefiklog/traefik.log
      - --accessLog.bufferingSize=100 # Configuring a buffer of 100 lines
      - --providers.docker=true
      - --providers.docker.defaultrule=Host(`{{ index .Labels "com.docker.compose.service" }}.xxx.com`)
      - --providers.docker.endpoint=unix:///var/run/docker.sock
      - --providers.docker.exposedByDefault=false
      - --providers.docker.network=t2_proxy
      - --providers.docker.swarmMode=false
      - --providers.file.directory=/rules # Load dynamic configuration from one or more .toml or .yml files in a directory.
      - --providers.file.watch=true # Only works on top level files in the rules folder
    networks:
      t2_proxy:
        ipv4_address: 192.168.90.254
    ports:
      - target: 443
        published: 443
        protocol: tcp
        mode: host
    volumes:
      - C:\docker/traefik/rules:/rules 
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - C:\docker/traefik/logs:/traefiklog
      - C:\docker/shared:/shared
    labels:
      - "traefik.enable=true"

  whoami:
    image: "containous/whoami"
    container_name: "whoami"
    networks:
      t2_proxy:
        ipv4_address: 192.168.90.200
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.whoami.rule=Host(`whoami.xxx.com`)"
      - "traefik.http.routers.whoami.entrypoints=https"
      - "traefik.http.routers.whoami.tls=true"

I set up the network with:

docker network create --gateway 192.168.90.1 --subnet 192.168.90.0/24 t2_proxy

and this is the output of the whoami webrequest in the browser:

Hostname: 8752e7b8a5d4
IP: 127.0.0.1
IP: 192.168.90.200
RemoteAddr: 192.168.90.254:36228
GET / HTTP/1.1
Host: whoami.xxx.com:433
User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US
Cache-Control: max-age=0
Dnt: 1
Te: trailers
Upgrade-Insecure-Requests: 1
X-Forwarded-For: 192.168.90.1
X-Forwarded-Host: whoami.xxx.com:433
X-Forwarded-Port: 433
X-Forwarded-Proto: https
X-Forwarded-Server: 969f601c0c24
X-Real-Ip: 192.168.90.1
2 Likes

Bump. Am I really the only one with this problem?

1 Like

I'm getting it as well. I've been looking around for anyone with a solution but not seeing anything so far. It's been a year since your last message, did you figure it out at all?

For anyone else encountering this problem, I found a workaround for this. I run a second treafik instance natively in windows forwarding traffic to the traefic instance in docker.
To get this to work I also had to move the SSL stuff to the outside instance and switch the internal one to http. I also had to add "forwardedHeaders.trustedIPs" to my entry point(s).