Docker Community Forums

Share and learn in the Docker community.

Accessing containers inside VM from other hosts on network (macvlan driver)


(Abourn) #1

Hello all, hoping someone can help with this!

Background:
I am running a series of containers inside a Ubuntu VM (running Virtualbox, provisioned with Vagrant), all of which are attached to a macvlan Docker network and are assigned their own IP addresses. The Ubuntu VM is running on top of macOS. I have a bridged network adapter between the VM and my host (which is set to promiscuous mode and is the “parent” interface of the macvlan network), meaning I can access the containers by IP address from my Mac.

What I want to accomplish:
Being able to access containers inside the VM from the host machine is great, but I really would like to access them from any host on my network. Currently, if I try to ping my containers from a device on the network (other than my Mac running the VM), the pings are unsuccessful. However, I am able to ping the VM’s address from other devices in my network just fine.

I feel like I need to define a static route somewhere, but I’m not sure where or if that is even the right approach.

If anybody has any guidance, it would be appreciated! I know this is a somewhat strange configuration to have, but it’s somewhat necessary for what I’m ultimately using this for. Thanks!


(Abourn) #2

Alright, I was able to get a step closer to solving my issue by using the ‘ipvlan’ driver. My best guess as to why this is is because macvlan is a layer 3 bridge while ipvlan is a layer 2 bridge. The following network create command made it so I was able to ping my containers from across the network.

docker network create -d ipvlan --subnet=192.168.1.0/24 --gateway=192.168.1.1 --ip-range=192.168.1.160/27 -o parent=eth1 -o ipvlan_mode=l2 test_net

However, this is not enough for me, since I also need unique MAC addresses for each one of my containers. Ipvlan does not assign unique MAC addresses (rather it will sit behind the parent interface’s MAC address). So it seems that I’ll probably have to use macvlan after all. Has anybody been able to address this issue?

If you don’t need unique MAC addresses like myself, then the following documentation should help:

You may have to turn on experimental functions in order for ipvlan to work. If you receive an error message after creating the network, try: https://stackoverflow.com/questions/44346322/how-to-run-docker-with-experimental-functions-on-ubuntu-16-04