So I'm trying to create a network (docker network create
) so that its traffic will pass through an specific physical network interface (NIC); I have two: <iface1>
(internal), and <iface2>
(external).
I need the traffics of both NICs to be physically separated.
METHOD 1:
I think macvlan
is the driver should use to create such network.
For most of what I found on the internet, the solutions refer to Pipework (deprecated now) and temporary docker-plugins (deprecated too).
For what most closely has helped me is this1
docker network create -d macvlan \
--subnet 192.168.0.0/16 \
--ip-range 192.168.2.0/24 \
-o parent=wlp8s0.1 \
-o macvlan_mode=bridge \
macvlan0
Then, in order for the container to be visible from the host, I need to do this in the host:
sudo ip link add macvlan0 link wlp8s0.1 type macvlan mode bridge
sudo ip addr add 192.168.2.10/16 dev macvlan0
sudo ifconfig macvlan0 up
Now the container and the host see each other :) BUT the container can't access the local network. The idea, is that the container can access internet.
METHOD 2:
As I will use <iface2>
manually, I'm ok if by default the traffic goes through <iface1>
.
But no matter in which order I get the NICs up (I also tried removing the LKM for <iface2>
temporarely); the whole traffic is always overtaken by the external NIC <iface2>
.
And I found that it happens because the route table updates automatically at some "random" time.
In order to force the traffic to go through <iface1>
, I have to (in the host):
sudo route del -net <net> gw 0.0.0.0 netmask 255.0.0.0 dev <iface2>
sudo route del default <iface2>
Now, I can verify (in several ways) that the traffic just goes through <iface1>
.
But the moment that the route table updates (automatically), all traffic moves to <iface2>
. Damn!
I'm sure there's a way to make the route table "static" or "persistent".
EDIT (18/Jul/2018): The main idea is to be able to access internet through a docker container using only one of two available physical network interfaces.