machine icon indicating copy to clipboard operation
machine copied to clipboard

[Feature Request] Specify a static IP for VirtualBox VMs

Open letsgolesco opened this issue 10 years ago • 213 comments

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!

letsgolesco avatar Aug 15 '15 22:08 letsgolesco

+1, need this feature

hanks avatar Aug 18 '15 13:08 hanks

+1

krancour avatar Aug 18 '15 20:08 krancour

+1

jsuksl avatar Aug 19 '15 01:08 jsuksl

+1

FlorianLoch avatar Aug 25 '15 21:08 FlorianLoch

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>)

krancour avatar Aug 25 '15 23:08 krancour

@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 avatar Aug 26 '15 14:08 luislavena

@luislavena - Unfortunately that did not work.

krinkere avatar Sep 11 '15 20:09 krinkere

+1

Def need this feature though!

krinkere avatar Sep 11 '15 20:09 krinkere

@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:

luislavena avatar Sep 11 '15 20:09 luislavena

Would love to see this feature!!

joaquinmoreira avatar Sep 13 '15 01:09 joaquinmoreira

@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

krinkere avatar Sep 14 '15 14:09 krinkere

+1 usefull feature

Kaycell avatar Sep 16 '15 08:09 Kaycell

+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.

jwebb-va avatar Sep 21 '15 19:09 jwebb-va

+1

regisxu avatar Sep 25 '15 01:09 regisxu

+1

wateryoma avatar Sep 26 '15 23:09 wateryoma

+1

florrain avatar Sep 28 '15 12:09 florrain

+1

fjallot avatar Sep 29 '15 09:09 fjallot

+1

davideuler avatar Sep 30 '15 05:09 davideuler

+1

alekzvik avatar Oct 01 '15 23:10 alekzvik

+1

Kroisse avatar Oct 02 '15 02:10 Kroisse

+1

ardydedase avatar Oct 06 '15 05:10 ardydedase

+1

oprearocks avatar Oct 07 '15 10:10 oprearocks

+1

ianlintner-wf avatar Oct 08 '15 15:10 ianlintner-wf

+1 (y)

simeonpashley avatar Oct 12 '15 19:10 simeonpashley

+1

MRylander avatar Oct 12 '15 22:10 MRylander

+1

nh avatar Oct 13 '15 15:10 nh

+1

gvisniuc avatar Oct 15 '15 13:10 gvisniuc

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 avatar Oct 16 '15 00:10 ianlintner-wf

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..

devopsguru avatar Oct 16 '15 03:10 devopsguru

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

ianlintner-wf avatar Oct 16 '15 16:10 ianlintner-wf