machine
machine copied to clipboard
[Feature Request] Specify a static IP for VirtualBox VMs
Hi, I've been searching through the docs and issues to figure this out but can't find an answer.
Basically, I want to be able to specify the IP address of a VM (i.e. the value that's listed under "URL" in docker-machine ls) when I create it with docker-machine create.
I want this because I've been relying on boot2docker's default address of 192.168.59.103, but now it varies from machine to machine.
Thanks!
+1, need this feature
+1
+1
+1
Here's a good workaround. Add the following to your ~/.bash_profile:
eval `docker-machine env <docker-machine name>`
export <some variable>=$(docker-machine ip <docker-machine name>)
@letsgolesco you can use --virtualbox-hostonly-cidr option for that, which will select the proper vboxnetX host-only adapter.
By default, seems docker-machine picks one randomly, so forced to use the one for vboxnet0 (192.168.59.3/24, the one used by boot2docker) seems to solve the issue:
$ docker-machine create --driver virtualbox --virtualbox-hostonly-cidr "192.168.59.3/24" dev
Creating VirtualBox VM...
Creating SSH key...
Starting VirtualBox VM...
Starting VM...
To see how to connect Docker to this machine, run: docker-machine env dev
$ docker-machine ip dev
192.168.59.103
Cheers.
@luislavena - Unfortunately that did not work.
+1
Def need this feature though!
@krinkere not sure your env, but this worked for my OSX installation by doing that, but failed when using machine on Linux, which required tweaks to dhcpserver configuration of vboxnet0:
$ VBoxManage dhcpserver modify --ifname vboxnet0 --disable
$ VBoxManage dhcpserver modify --ifname vboxnet0 --ip 192.168.59.3 --netmask 255.255.255.0 --lowerip 192.168.59.103 --upperip 192.168.59.203
$ VBoxManage dhcpserver modify --ifname vboxnet0 --enable
$ docker-machine create --driver "virtualbox" --virtualbox-cpu-count "-1" --virtualbox-disk-size "30000" --virtualbox-memory "2560" --virtualbox-hostonly-cidr "192.168.59.3/24" dev
This is, as you can see, a huge hack :smile_cat:, but works for now :smile:
Would love to see this feature!!
@luislavena - Thanks for your response
Here is what I get on my Mac.
$ docker-machine create --driver virtualbox --virtualbox-hostonly-cidr "192.168.99.3/24" dev Creating VirtualBox VM... Creating SSH key... Starting VirtualBox VM... Starting VM... To see how to connect Docker to this machine, run: docker-machine env dev
$ docker-machine ip dev 192.168.99.100
While I do have ip in the right subnet, it is not the IP that I would want to use... Def would love to see this feature
+1 usefull feature
+1 This feature would really help us out!
We use docker-machine to run a local Elasticsearch cluster and we have /etc/hosts entry for 192.168.59.103 which maps to elastic-local.mycompany.com. Since we have moved over to docker-machine from boot2docker, we have had to continuously manually update this hosts file entry to whatever is the new IP assigned to our docker VM. We could write some automation which would update this hosts file entry for us but it would be much simpler if docker-machine just let us use a configurable IP address for new machines.
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1 (y)
+1
+1
+1
Temporarily I am using some bash scripts to update the hosts files but is kludgy since you have to update /etc/hosts via sudo'd script but since you can get ip from docker-machine it works. I may share a gist.
ianlintner-wf, do share the script please. I'm about to write one exactly like that myself, but if I can not reinvent the wheel that'd be great.. yeah..
Here is the primary script I am using. I cleaned it up a little, but it lacks more formal default params and other stuff.
https://gist.github.com/ianlintner-wf/a2b917158aaf100d9fb3