Find Requester ip address

Hi, i have problem to find a requester’s ip

I have docker compose with 2 containers:

  • frontend
    - port :
    3000:3000
  • backend
    - port :
    8000:8000

When request to frontend container and then the frontend container request to backend container , the requester’s ip is a ( backend container Ip ) !

Shouldn’t it be a 127.0.0.1 ?!?
Or my system IPV4 ?!?

A container in a bridge network can not see the source ip of a request. It will see the bridge networks gateway as source ip.

If you need to retain the source ip, the container must either use the host network or use a macvlan or ipvlan network.

This can only be true, if the container uses the host network, and you either use one of both in the URL to access the container.

What is your solution for Windows os?

Docker Desktop for Windows? I am afraid none.

Yes in windows desktop ;(
I can’t change my os and i should fix it on win

You could run a reverse proxy on your windows host (e.g. like nginx, apache, or traefik) and inject the X-Forwarded-For header, and make your containers read the source ip from the header.

Treafik has a binary release that could be used: Traefik Installation Documentation - Traefik + the file provider example should help you configure Traefik for your needs. The same should exist for nginx and apache.

Here is a poc for traefik.

Download the binary release, extract the zip and place these two files with this content in the same folder as traefik.exe.

file_provider.yml:

entryPoints:
  web:
    address: :80

providers:
  file:
    filename: ./dynamic_conf.yml

dynamic_conf.yml:

# http routing section
http:
  routers:
    frontend:
      rule: "Host(`localhost`) && PathPrefix(`/frontend/`)"
      middlewares:
      - fronted-stripprefix
      service: frontend
    backend:
      rule: "Host(`localhost`) && PathPrefix(`/backend/`)"
      middlewares:
      - backend-stripprefix
      service: backend

  middlewares:
    fronted-stripprefix:
      stripPrefix:
        prefixes:
          - "/frontend/"
    backend-stripprefix:
      stripPrefix:
        prefixes:
          - "/backend/"

  services:
    frontend:
      loadBalancer:
        servers:
        - url: http://localhost:3000/
    backend:
      loadBalancer:
        servers:
        - url: http://localhost:8000/

Then run treafik with ./traefik --configfile file_provider.yml in the folder. Then you can reach the frontend using http://localhost/fronend/ and the backend using http://localhost/backend/.

If you modify your hosts file (c:\Windows\System32\drivers\etc\hosts) as admin, you can add arbitrary domain names and resolve them to 127.0.0.1. Then you could use those hosts in http.router rules and remove the PathPrefix and the middleware.

Traefik should inject common x-headers by default to the forwarded request.