April 15, 2023, 9:32pm
Hi, i have problem to find a requester’s ip
I have docker compose with 2 containers:
- port :
- port :
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 ?!?
April 16, 2023, 11:12am
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.
April 16, 2023, 2:18pm
What is your solution for Windows os?
April 16, 2023, 2:25pm
Docker Desktop for Windows? I am afraid none.
April 16, 2023, 2:32pm
Yes in windows desktop ;(
I can’t change my os and i should fix it on win
April 16, 2023, 3:37pm
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.
April 16, 2023, 4:38pm
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.
# http routing section
rule: "Host(`localhost`) && PathPrefix(`/frontend/`)"
rule: "Host(`localhost`) && PathPrefix(`/backend/`)"
- url: http://localhost:3000/
- 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
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.