Close

Docker macvlan with host access

bastelbausBastelBaus wrote 3 days ago • 2 min read • Like

Setting up a macvlan in docker has an irritating fact that the host cannot be reached from the container and the host itself cannot reach the container.

Most people propose to add a second macvlan to the ethernet interface to allow routing between docker container and host. The drawback is, that this setup involves manual work for the container user.

I think I came up with an elegant solution (at least for me) to solve this; 

a) add a second (default bridge) network to the container (see A & B)
b) add a routing rule inside the container to route trafic to the host via this second interface -> allow container to host traffic (see C)
c) As usual, expose ports on this default interface -> allows host to container traffic

Benefits:
- Can be configured completely inside a container (i.e. startup script) and with a docker compse file ==> easy for users!

Example / proof of concept for a host at 192.168.0.22 hosting a docker container:

A) docker-compose with a macvlan network at 192.168.0.28:

B) The resulting network configurationC) Non reachable host and ip-route setting in the container to reach host again

Like

Discussions