0

I want to assign different IP on different Docker. I have created an ubuntu instance on AWS, with 2 network interfaces. Running ifconfig on the ubuntu host, there are eth0 and eth1. May I know how to assign eth0 or eth1 manually to different Docker container?

Thanks.

ロジャー
  • 347
  • 1
  • 6
  • 16
  • You can use `docker run -p :80:80 nginx` to run nginx just on eth0 ip. Is this what you want? – Tarun Lalwani Sep 14 '17 at 13:47
  • This is useful for my future usage, since I am new to multi-IP issue. But what I want this time is that, the Internet traffic from each Docker container goes through different network interfaces. i.e. data from container-1 goes through eth-1-on-host, container-2 goes through eth-2-on-host. Hence, CURL myipaddress.com on different container shows different IP. – ロジャー Sep 14 '17 at 14:10
  • See these https://github.com/moby/moby/issues/30053, https://superuser.com/questions/1069964/force-container-outbound-traffic-via-another-container-without-host-iptables-ru, https://unix.stackexchange.com/questions/338951/route-outging-traffic-from-private-network-lxdbr0 – Tarun Lalwani Sep 14 '17 at 14:53
  • I see. Actually I have a python program inside the containers. Do you think setting "host" mode letting the containers seeing all the network interfaces, and selecting the specific interface inside the python program would be a better choice? https://stackoverflow.com/questions/38310650/how-to-use-python-requests-with-a-server-that-has-two-ip-addresses/38310760#38310760 – ロジャー Sep 14 '17 at 16:57
  • 1
    I think whatever works for you with least effort and mess is what you should use – Tarun Lalwani Sep 14 '17 at 17:01
  • Thank you for the links. I hope there will be outgoing-ip in future docker releases! – ロジャー Sep 14 '17 at 17:05
  • I am trying these two commands. "docker network create NETWORK --subnet=192.168.1.0/24 --gateway=192.168.1.1" and "iptables -t nat -I POSTROUTING -s 192.168.1.0/24 -j SNAT --to-source OUTGOING_IP". I choose "255.255.255.252/30" as the subnet-mask, since I need some subnet, but inside each subnet there is only one user. However, as I understand, the "iptables" routes the traffic according to subnet-mask. What should I do to make it routes according to subnet ID/IP? – ロジャー Sep 15 '17 at 06:19
  • Post a new question with proper tags likes iptables, because I am not a networking expert – Tarun Lalwani Sep 15 '17 at 06:20

0 Answers0