Docker and UFW with real IP
I have a docker setup which disabled its default behaviour of tampering with
iptables. So all works perfectly fine that I can allow or block specific port to outside world by specifying rule on
ufw. Until I found the problem of not able to access the real IP of client accessing the website. All I see is 18.104.22.168 inside my container which is the IP
I found a solution that asked me to add the below to my
iptables -t nat -A PREROUTING ! -i docker0 -p tcp --dport 80 -j DNAT --to-destination 172.17.0.7:80
172.17.0.7 is the IP of proxy container. Now the problem is this IP tend to change if it happen to reboot and then my rule will no longer be valid.
Is there any elegant way of solving this issue without going in the route of assigning static IP to containers if at all it is possible.
Let me know if you need to see any more details of my setup. I am happy to post them.
One Solution collect form web for “Docker and UFW with real IP”
You can try running dockerd without the userland proxy, which is the process that masks the IP.
There are various issues in doing that though.
Otherwise routing “real” IP’s to containers is the cleanest solution.