I run a few Linux containers, each running a webapp, on my Ubuntu host. To access the webapps, I use iptables
to forward port:
sudo iptables -t nat -A PREROUTING -p tcp --dport <port> -j DNAT --to-destination #<container_ip>:<port>
This work well if the traffic comes from outside of my host. If the request is done by localhost it doesn't work:
curl <host_ip>:<port> #works (from outside the host)
curl <container_ip>:<port> #works (from inside the host)
curl 127.0.0.1:<port> #doesn't work (from inside the host)
I understand that packet coming from localhost do not go through the iptables DNAT rule and that is why it's not working. Is there anyway to get this working ?