Skip to content

Instantly share code, notes, and snippets.

@nerdalert
Last active March 13, 2016 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nerdalert/8ef7df406b1c95a41cd6 to your computer and use it in GitHub Desktop.
Save nerdalert/8ef7df406b1c95a41cd6 to your computer and use it in GitHub Desktop.
  • Host configuration is two interfacces:
$ ip a show eth0
   eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
       link/ether 00:50:56:2b:29:40 brd ff:ff:ff:ff:ff:ff
       inet 172.16.86.151/24 brd 172.16.86.255 scope global eth0
       
$ ip a show eth1
   eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
       link/ether 00:50:56:39:45:2e brd ff:ff:ff:ff:ff:ff
       inet 192.168.1.251/24 brd 192.168.1.255 scope global eth1

$ ip route
    default via 172.16.86.2 dev eth0
    10.1.1.0/24 dev eth2  proto kernel  scope link  src 10.1.1.251
    172.16.86.0/24 dev eth0  proto kernel  scope link  src 172.16.86.151
    172.17.0.0/16 dev docker0  proto kernel  scope link  src 172.17.0.1
    192.168.1.0/24 dev eth1  proto kernel  scope link  src 192.168.1.251
  • The first two networks created are isolated since no parent is specified.
  • The second two can reach externally as they are using the host interfaces listed above. Those two interfaces have gateways of 192.168.1.1 and 172.16.86.2 which are spcified in the docker network create commands below.
# Nil Parent Ipvlan (Containers are isolated if no parent is specified)
docker network create -d ipvlan ipv

# Nil Parent Macvlan (Containers are isolated if no parent is specified)
docker network create -d macvlan mcv

# Ipvlan Mode:L2 Parent:eth0 = 172.16.86.151/24  (see host IP configuration above)
docker network create -d macvlan \
    --subnet=172.16.86.0/24 \
    --gateway=172.16.86.2 \
    -o parent=eth0 mcv

#  -Parent eth1 192.168.1.250/24 
# Ipvlan Mode:Bridge Parent:eth1 = 192.168.1.251/24 (see host IP configuration above)
# docker network create -d ipvlan \
    --subnet=192.168.1.0/24 \
    --gateway=192.168.1.1 \
    -o parent=eth1 ipv

# Start containers
docker run --net=mcv -it --rm alpine /bin/sh
# Start containers
docker run --net=ipv -it --rm alpine /bin/sh

# Ipvlan 1-liner: network + container
docker network create -d ipvlan --subnet=192.168.1.0/24 --gateway=192.168.1.1 -o parent=eth1 ipv && docker run --net=ipv -it --rm alpine /bin/sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment