I have a pair of docker containers running on the host machine, these containers together makes my application fulfill. So for each iteration/instance of my application requires a pair of docker containers to run. So far I'm using the --link parameter while running the second container to link the first container and get the IP of the first container from hosts file to use it programmatically.
Now, I need to setup a transparent proxy for the second docker container. so that, all http (port 80) traffic of the second container should be going through the port 8080 of the first container.
First container IP: 172.17.0.4 (Has proxy service running on port 8080). Second container IP: 172.17.0.6 (Has client tools like browser). I wanted to forward all http traffic (Port 80) of the 172.17.0.6 to the port 8080 of the 172.17.0.4.
i.e) Traffic to 80 of 172.17.0.4 <---> 8080 of 172.17.0.6
I have tried adding the iptables rules inside the second container for the above configuration. But none of them worked.
~# sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 172.17.0.4:8080
~# sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 172.17.0.4:8080
~# sudo iptables -t nat -A POSTROUTING -j MASQUERADE
So my question is, how can I configure a transparent proxy inside a docker container that can forward all traffic of a specified port to another container's port?
P.S: If I manually add the proxy settings to the browser in the second container. It is working fine. But I wanted to set the transparent proxy for the entire container, not only the browser. so that any network request from any tool inside the second container will be forwarded to the first container's proxy port.
I have read some tutorials on reverse-proxying the all the containers running together using nginx/HAProxy. But I wanted to configure individual container with it's own proxy container as a pair.