Trying to set docker-machine to fixed IP, but it keeps changing back

Greetings.

I tried to fix my docker-machine vm to a fixed ip 192.168.99.101 by following this: fixIP4dm

It was at first successful. But a while later, it gets changed back to the original 192.168.99.105, and I had to do the same again. If I delete and recreate it again, it ends up with 192.168.99.106, and the number keeps going up with every new creation, and that happens even after I kill the DHCP process.

I also tried to use the option --virtualbox-hostonly-cidr to fix the address as one suggested, though I don’t understand what that means.

docker-machine create -d virtualbox --virtualbox-hostonly-cidr=“192.168.99.101/32” swarmmgr

But it doesn’t work at all gives this “Error creating machine: Error in driver during machine creation: Error setting up host only network on machine start: host-only cidr must be specified with a host address, not a network address”

Would anyone who has been been successful in setting a permanent fixed IP to a docker-machine VM share some experience and insight? or point out what I’m doing wrong.

thanks much!
Ben

Hello,

you haven’t say if you’re on Linux and if it should be an IP on your host’s network.

If that is the case, then you can create a new Docker network using the macvlan driver and assigning fixed IPs in compose files. Works perfectly on Ubuntu.

Actually I use a script to create/remove such a network when I need it.

If that’s what you would need, I could publish the script on GitHub.

Regards
accetto

Hi Accetto,

thanks so much for sharing this!

Yes, I’m on Ubuntu 16.04. Will read about macvlan. It would be great if you can share the script that embodies your insight.

thanks a lot,
Ben

Sorry, I have trouble to spare time for preparing the script for publishing. But I’ve been inspired by this blog article: https://blog.oddbit.com/post/2018-03-12-using-docker-macvlan-networks/

Hopefully it helps.