As described in earlier articles, I’m using an ephemeral virtual machine to run a privileged container with access to the Docker docker of the virtual machine as a system to build Docker images in a CI pipeline. Occasionally, one of the machines hosting the virtual machines breaks and stops spinning up new virtual machines on demand. The pending docker-machine instances display the error message

Could not find matching IP for MAC address

Here is why and how to solve it until this is fixed upstream.

The cause

With the default setup and VirtualBox as the backend, virtual machines managed by docker-machine receive an IP address from a class C subnet of 192.168.0.0, e.g., 192.168.45.123/24. VirtualBox manages a DHCP server responsible for the assignment. It picks an address in the 100-254 range. Depending on the number of docker-enabled CI jobs, the range of IP addresses is exhausted after hours or months. If you hit the limit within hours, there is nothing the DHCP server could do. It issued IP address leases with a validity of usually 24 hours. So, the address might be reclaimed and assigned to a new ephemeral machine only after the old lease expired.

If there are not so many jobs, and you hit the limit after, let’s say, a month, it’s probably safe to assume that one of the earliest leases has expired. The thing is, the DHCP does not reclaim the IP addresses even after the lease expired. As a result, the IP address counter never wraps around and does not restart at 192.169.x.100/24. The issue has also been discussed in the VirtualBox forums.

The workaround

The only way I found to reset the DHCP server is to kill it. This might not be the best solution, and if you have other non-ephemeral virtual machines currently running, be prepared that their IP address will change.

$ ps ax | grep VBoxNetDHCP 
# Note process number
$ kill -9 PID

Have you found a better solution? Let me know.