I have created User-defined network and used that in my compose file:
version: "3" services: proxy: build: ./proxy networks: - network1 app: build: ./app networks: - network1 networks: network1: driver: custom-driver-1
Now both containers are connected to the same network.
How can I create iptable rules or gateway to guide all the traffic from app container to proxy container and then to the external web (without changing or creating iptable rules in host…)?
I am completely new in routing, linux gateway and iptables. I want to transfer my system from virtualbox to docker (I have created such system in virtualbox with app running in internal network (combining some tutorials)).
Iptable rules I use in virtualbox proxy machine:
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080 sudo iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 8080 sudo iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE