After trying for days I hope someone can help me out over here.

I would like to connect a docker to the secondary IP on my virtual host, where the applications in the docker use eth0.

The good news is that a ping outside my docker to the secondary IP works (‘ping -I 107.233.216.241 www.google.com’).

I’ve setup a user network (macvlan) as well using:
docker network create -d macvlan --subnet=107.233.216.241/24 --gateway=107.233.216.254 my-macvlan-net

PS: I’m not completely sure about the gateway, but I used extension 254 because my main IP uses the same gateway, and if I ommit this parameter it is set to extension 1, which doesn’t work either.


Then I connected via:

docker run --rm -dit --network my-macvlan-net --name my-macvlan-alpine --ip 107.233.216.241 alpine:latest ash

Now a ping to Google from within the docker yields:
ping: bad address ‘www.google.com


(note that a ping to an existing IP just doesn’t give data back)


An ‘ip a’ from within the docker gives:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
117: eth0@if116: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP
link/ether 02:42:6d:ed:d8:f0 brd ff:ff:ff:ff:ff:ff
inet 107.233.216.241/24 brd 107.233.216.255 scope global eth0
valid_lft forever preferred_lft forever

And an ‘ip route’ from within the docker gives:
default via 107.233.216.254 dev eth0
107.233.216.0/24 dev eth0 scope link src 107.233.216.241


Any tips to help me out?