I want to know client_real_ip But always return 172.0.0.1 or My laptop_ip
How to solve ??
OS : m1 mac
–network host is not working
Here is my case
Client_ip : 111.111.1.1
MyLaptop_ip : 222.222.2.2
Docker_container_server_ip : 172.0.0.1
-
The client will send a request to the container server
-
Then the request will arrive at my laptop first and from my laptop it will be sent to the container.
-
in container_server, request.client.host is always 172.0.0.1 or 222.222.2.2
I don’t want this ip , I want to client_ip 111.111.1.1(real client ip)
I think we should be able to send the request coming to the laptop to the container as it is. So that Docker doesn’t convert it internally and send it
I think I need to tweak the docker settings, but I don’t know what to do.
2
Answers
Host networking might help:
Here is an example of a docker-compose.yml file:
A little update on your comment, please also consider this: container to host
It is because of the NAT that is done by Docker. Maybe this can help or you can also try https://docs.docker.com/network/host/.
Note: Host networking mode only works on Linux Host. As for Docker for Mac and Windows has a small packaged Linux kernel on which it is actually run.