I’ve previously written about using macvlan networks with docker, this has proved to be a great way to make containers more like lightweight VMs as you can assign a unique IP on your network to them. Unfortunately when I did this I only allocated 4 IPs to the network, and 1 of those is used to provide a communication path from the host to the macvlan network.
Here is how I’ve used up those 4 IPs:
- wireguard – allows clients on wireguard to see other docker services on the host
- mqtt broker – used to bridge between my IoT network and the lan network without exposing all of my lan to the IoT network
- nginx – a local only webserver, useful for fronting Home Assistant and other web based apps I use
- shim – IP allocated to supporting routing from the host to the macvlan network.
If I had known how useful giving a container a unique IP on the network was, I would have allocated more up front. Unfortunately you can’t easily grow a docker network, you need to delete and recreate it.
As an overview here is what we need to do.
- Stop any docker container that is attached to the macvlan network
- Undo the shim routing
- Delete the docker network
- Recreate the docker network (expanded)
- Redo the shim routing
- Recreate the existing containers
This ends up not being too hard, and the only slightly non-obvious step is undoing the shim routing, which is the reverse of the setup.
1 2 3 4 |
$ sudo ip route del 192.168.1.64/30 dev myNewNet-shim $ sudo ip link set myNewNet-shim down $ sudo ip addr del 192.168.1.67/32 dev myNewNet-shim $ sudo ip link del myNewNet-shim link enp3s0 type macvlan mode bridge |
The remainder of this post is a walk through of setting up a 4 IP network, then tearing it down and setting up a larger 8 IP network.