Docker Community Forums

Share and learn in the Docker community.

How to use experimental macvlan networks on Docker for Mac?

beta

(Mcrawford) #1

Relatively new to this… Still experimenting, can’t find an answer to this question so far.

I’m hoping to switch from using VMware Fusion to host DNS, PXE, BIND in VMs on a Mac Mini to running these services via containers via Docker for Mac Beta. This requires me to create these containers with fixed IP addresses on the Mac’s primary network. I’m currently using DHCP with mac-address reservations, but it seems that’s not yet ready with the macvlan driver, so I have to specify an IP address when I run the container.

I’ve tested this a bit on a Fusion VM running Ubuntu 16.04 within an iMac, which has the VMware NAT network and a bridged network setup, exposed within the Ubuntu VM as ens33: 192.168.40.152/24 and ens34: 10.0.1.152/24 respectively. After installing docker experimental, I create a network using:

docker network create -d macvlan --subnet=10.0.1.0/24 --gateway=10.0.1.1 --ip-range=10.0.1.160/28 -o parent=ens34 network1

And am then able to run a container with a specified IP on this network using:

docker run -td --name “container1” --hostname “container1”
–network=network1 --ip=10.0.1.165 alpine ash

I can then connect to the container and ping other hosts or ping this container from other hosts:

docker exec -it continer1 ash
/ # ping 10.0.1.1 # ping router
/ # ping 10.0.1.8 # ping other VM running on parent mac
/ # ping 10.0.1.192 # ping the parent mac
/ # exit

So far, when I’m setting up the VM via Fusion inside the Mac, then installing docker myself and creating the network myself from within the docker VM, it looks like I can do what I want.

Where I’m having trouble and could use some help, is how do I do the same thing using Docker for Mac Beta? Here, I think the docker command is running on the Mac, but communicating with a VM created via Hyperkit/xhyve/bhyve running docker-engine, but I don’t know how to get in to that VM to see what interface I’d use in the docker network command as the interface to which the macvlan driver connects (i.e. “-o parent=ens34”) in my working example. I’ve tried en0 (but that’s the parent mac’s interface, not an interface on the embedded VM) or guessed at “eth0”, but neither seemed to work.

So, any idea of what I should fix in this statement:

docker network create -d macvlan --subnet=10.0.1.0/24 --gateway=10.0.1.1 --ip-range=10.0.1.160/28 -o parent=eth0 network1

Assuming:

  • The mac’s wired interface is en0, set to 10.0.1.192/24
  • I want to docker containers running network services to be in range 10.0.1.160-175, initially via static IP, then via defined mac address and DHCP-provided IP address once that’s ready.
  • I want to be able to reach BIND DNS servers from other HW and virtual hosts on the 10.0.0.0/16 network

Thanks!


(Walid A. Shaari) #2

you seem to be doing alright with Fusion, did you try playing with docker-machine? for example

mms-iMac:~ mms$ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
default - virtualbox Running tcp://192.168.99.100:2376 v1.12.3

also check that slides, as they had some hints/warning http://www.slideshare.net/bbsali0/docker-networking-with-new-ipvlan-and-macvlan-drivers