docker / machine

Machine management for a container-centric world
https://docs.docker.com/machine/
Apache License 2.0
6.63k stars 1.97k forks source link

[Feature Request] Specify a static IP for VirtualBox VMs #1709

Open letsgolesco opened 9 years ago

letsgolesco commented 9 years ago

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!

hanks commented 9 years ago

+1, need this feature

krancour commented 9 years ago

+1

jsuksl commented 9 years ago

+1

FlorianLoch commented 9 years ago

+1

krancour commented 9 years ago

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>)
luislavena commented 9 years ago

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

krinkere commented 9 years ago

@luislavena - Unfortunately that did not work.

krinkere commented 9 years ago

+1

Def need this feature though!

luislavena commented 9 years ago

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

joaquinmoreira commented 9 years ago

Would love to see this feature!!

krinkere commented 9 years ago

@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

Kaycell commented 9 years ago

+1 usefull feature

jwebb-va commented 9 years ago

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

regisxu commented 9 years ago

+1

wateryoma commented 9 years ago

+1

florrain commented 9 years ago

+1

fjallot commented 9 years ago

+1

davideuler commented 9 years ago

+1

alekzvik commented 9 years ago

+1

Kroisse commented 9 years ago

+1

ardydedase commented 9 years ago

+1

oprearocks commented 9 years ago

+1

ianlintner-wf commented 9 years ago

+1

simeonpashley commented 9 years ago

+1 (y)

MRylander commented 9 years ago

+1

nh commented 9 years ago

+1

gvisniuc commented 9 years ago

+1

ianlintner-wf commented 9 years ago

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.

devopsguru commented 9 years ago

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

ianlintner-wf commented 9 years ago

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

cookandy commented 9 years ago

+1 please!

cookandy commented 9 years ago

thanks for the script @ianlintner-wf. I have written one that dynamically adds the host/ip of any running docker machines. Have tested on OS X El Capitan.

https://gist.github.com/cookandy/f14fadd31721dc6e136e

xwang-gobalto commented 9 years ago

The IP increment is cached by VirtualBox DHCP server. Stop and restart VirtualBox will reset the IP increment.

jcpst commented 9 years ago

+1, our OSX devs are still using boot2docker because our env relies on static /etc/hosts entries. (btw thanks for the script @ianlintner-wf )

brandonsimpson commented 9 years ago

+1

webfella commented 8 years ago

+1

Plimsky commented 8 years ago

+1

0mega commented 8 years ago

+1

kgx commented 8 years ago

+2

jwalton commented 8 years ago

My hacky-hack solution, which is definitely not for everyone: I'm running Cassandra in a docker machine, and I want to be able to get to it from the node.js app I'm developing. Rather than use a fixed IP for the docker machine, I do:

docker-machine stop dockervm
VBoxManage modifyvm "dockervm" --natpf1 "tcp-port9160,tcp,,9160,,9160"
VBoxManage modifyvm "dockervm" --natpf1 "tcp-port9042,tcp,,9042,,9042"
docker-machine start dockervm
eval "$(docker-machine env dockervm)"

which enables port forwarding for port tunnelling from localhost to the docker VM. Now I can just connect to localhost:9042. (This would be much easier if someone were to fix https://github.com/docker/machine/issues/41. :D)

define-null commented 8 years ago

@luislavena thank you, just recreated default machine with these options and everything works fine now

blazarecki commented 8 years ago

+1

jgsqware commented 8 years ago

+1, I will try the script with the automatic update of hosts file, but definitely I want this feature!

jgsqware commented 8 years ago

Based on @cookandy & @ianlintner-wf script, I've created mine.

You can configure it with a map between docker-machine-name and host name.

It will update your hosts by removing older docker machine ips and a new ones

https://gist.github.com/juliengarcia/9a208ca5cf6590b25150

chhaj5236 commented 8 years ago

+1

bootjp commented 8 years ago

:+1:

manojlds commented 8 years ago

+1

uchagani commented 8 years ago

+1

tonivdv commented 8 years ago

:+1:

Hengjie commented 8 years ago

+1