Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

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

Open
letsgolesco opened this issue Aug 15, 2015 · 213 comments
Open

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

letsgolesco opened this issue Aug 15, 2015 · 213 comments

Comments

@letsgolesco
Copy link

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
Copy link

hanks commented Aug 18, 2015

+1, need this feature

@krancour
Copy link

+1

1 similar comment
@jsuksl
Copy link

jsuksl commented Aug 19, 2015

+1

@nathanleclaire nathanleclaire changed the title Specify IP address of new VM? [Feature Request] Specify a static IP for VirtualBox VMs Aug 19, 2015
@FlorianLoch
Copy link

+1

@krancour
Copy link

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
Copy link

@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
Copy link

@luislavena - Unfortunately that did not work.

@krinkere
Copy link

+1

Def need this feature though!

@luislavena
Copy link

@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 😸, but works for now 😄

@joaquinmoreira
Copy link

Would love to see this feature!!

@krinkere
Copy link

@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
Copy link

Kaycell commented Sep 16, 2015

+1 usefull feature

@jwebb-va
Copy link

+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
Copy link

regisxu commented Sep 25, 2015

+1

9 similar comments
@wateryoma
Copy link

+1

@florrain
Copy link

+1

@fjallot
Copy link

fjallot commented Sep 29, 2015

+1

@davideuler
Copy link

+1

@alekzvik
Copy link

alekzvik commented Oct 1, 2015

+1

@Kroisse
Copy link

Kroisse commented Oct 2, 2015

+1

@ardydedase
Copy link

+1

@oprearocks
Copy link

+1

@ianlintner-wf
Copy link

+1

@simeonpashley
Copy link

+1 (y)

@MRylander
Copy link

+1

1 similar comment
@nh
Copy link

nh commented Oct 13, 2015

+1

@gvisniuc
Copy link

+1

@tombusby
Copy link

tombusby commented Jan 26, 2017 via email

@nathanleclaire
Copy link
Contributor

nathanleclaire commented Jan 26, 2017

I'm all for spamming the subscribers.
Some of those subscribers are part of the project team.

Maintainer checking in. Please do not do spam the issue with +1 comments. This is a well known issue and spamming the thread doesn't do any good. Indicate support through the "+1" emoji reactions if you'd like. As always, we're happy to evaluate pull requests or detailed proposals. Thanks all.

(As a side note, @twang2218 seems to have the right idea generally -- static IPs are trickier than they look to get right and hit the use cases subscribers to this thread might have in mind -- perhaps an issue could be started in the boot2docker repo to discuss.)

@aniljose72
Copy link

I do not really want a static ip. But once the ip address is picked during creation, it should keep it on subsequent restarts. Is this already available?

@desimaniac
Copy link

desimaniac commented Apr 2, 2017

I had a docker with VPN and the standard 192.168.99.100 wasn't loading. I figured this was because of the VPN connection, so I setup a bridge network inside Virtualbox to access the docker via 192.168.1.159. I would like this to show up on Kitematic's published IP address. Is there any way to do so?

@joelhandwell
Copy link

joelhandwell commented Apr 3, 2017

For those who can not wait this feature to be implemented, assigning custom ip, plus custom cpu/memory is possible by using Vagrant VirtualBox provider and docker-machine generic driver.

For example in windows, place this Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.box = "AlbanMontaigu/boot2docker"
  config.vm.provider "virtualbox" do |v|
    v.memory = 8192
    v.cpus = 8
  end
  config.vm.synced_folder ".", "/vagrant", disabled: true
  config.vm.synced_folder "C:/Users", "/c/Users"
  config.vm.network "private_network", ip: "192.168.99.103"
end

and place vagrant default ssh private key with name vagrant.pem

and run

vagrant up
docker-machine create --driver generic --generic-ip-address=192.168.99.103 --generic-ssh-user=docker --generic-ssh-key=vagrant.pem default
docker-machine ls

and you'll get docker host with custom ip, cpu, memory etc configured via vagrant at the same time accessible via docker-machine.

You can find working file set for Windows in https://github.com/joelhandwell/dockerhost

joelhandwell added a commit to joelhandwell/dockerhost that referenced this issue Apr 10, 2017
@ahilbig
Copy link

ahilbig commented Jul 10, 2017

@jcwilson Hi Josh et al, thanks a lot.. I forked your script in order to fix the same issue (see minishift/minishift#343 , minishift/minishift#598) in combination with minishift:

https://github.com/ahilbig/docker-machine-ipconfig

@mahnunchik
Copy link

Any news?

@gbraad
Copy link
Contributor

gbraad commented Aug 23, 2017

Currently, I am experimenting with this for Minishift: minishift/minishift#1293
Although, another approach would be to use something like cloud-init (which is maybe to heavy for this approach, or embed a DHCP server inside the Go-based binary and use this to force an allocated IP address)

@D33M
Copy link

D33M commented Aug 25, 2017

+1.
Currently having more than one machine is horrific pain. If you use additional certificates (for example, for custom docker repository) and change order of starting machines, you have to do:

Error checking TLS connection: Error checking and/or regenerating the certs: There was an error validating certificates for host "192.168.99.100:2376"
: x509: certificate is valid for 192.168.99.101, not 192.168.99.100

This forces you to regenerate certificates or disable all machines and restore order of executing (what sometimes can be painful, too).

Additionally, using Chef to configure Docker-based project would also be much better if you could assume created machine would have always the same IP (for example, adding it to hosts file and you could forget about IPs).

@asishtom
Copy link

+1

1 similar comment
@tnguven
Copy link

tnguven commented Sep 20, 2017

+1

@luizhpriotto
Copy link

luizhpriotto commented Sep 27, 2017

+1
thx jcwilson, the script docker-machine-ipconfig is very good! i needed to alter the eth1 to eth0 in the script, after this, the script working perfect for me. I'm use vmware vsphere.

bye.

@vanhoutenbos
Copy link

+1

@gbraad
Copy link
Contributor

gbraad commented Nov 27, 2017

As part of minishift, we have implemented minishift/minishift#1316 and this has been working well so far. We are now looking into alternatives to do the same for the other hypervisors over time, but first we will fix the address using minishift/minishift#1457 (to prevent a new address from being assigned). We haven't been able to reserve time yet, we are going to land this in minikube too.

@amoussa78
Copy link

+1

@maciekkreft
Copy link

The simplest workaround which I found is to rely on sequence of starting virtual machines by doker-machine.

VirtualBox has DHCP server which starts assigning IP adresses from 192.168.99.100.

  1. Stop all VMs
    docker-machine stop ${docker-machine ls -q}
    This step will release all assigned addresses to VirtualBox DHCP

  2. Start VMs in order
    docker-machine start vbox1 && docker-machine start vbox2 && docker-machine start vbox3
    This steps assign IP like this:
    192.168.99.100 : vbox1
    192.168.99.101 : vbox2
    192.168.99.102 : vbox3

Notice that docker-machine start vbox1 vbox2 vbox3 will not work, but I don't figure out why.

@provodok
Copy link

provodok commented May 3, 2018

+1

@fcying
Copy link

fcying commented Feb 3, 2019

when i run docker-machine.exe start, it takes more than 15 sec for DHCP waiting for an IP(if internet is broken, it takes more than 2minutes), i think if can set a static ip, it can boot fast.

@gbraad
Copy link
Contributor

gbraad commented Feb 3, 2019 via email

@arikw
Copy link

arikw commented Feb 27, 2019

The simplest workaround which I found is to rely on sequence of starting virtual machines by doker-machine.

VirtualBox has DHCP server which starts assigning IP adresses from 192.168.99.100.

  1. Stop all VMs
    docker-machine stop ${docker-machine ls -q}
    This step will release all assigned addresses to VirtualBox DHCP
  2. Start VMs in order
    docker-machine start vbox1 && docker-machine start vbox2 && docker-machine start vbox3
    This steps assign IP like this:
    192.168.99.100 : vbox1
    192.168.99.101 : vbox2
    192.168.99.102 : vbox3

Notice that docker-machine start vbox1 vbox2 vbox3 will not work, but I don't figure out why.

Sometimes I had to kill VBoxNetDHCP.exe process on Windows, to make vbox assign IPs starting from 192.168.99.100
Otherwise, vbox would not release IPs used by previous machines (not sure why)

@wontheone1
Copy link

👍

@wontheone1
Copy link

It would really make my life easier.

@burtsevyg
Copy link

The simplest workaround which I found is to rely on sequence of starting virtual machines by doker-machine.

VirtualBox has DHCP server which starts assigning IP adresses from 192.168.99.100.

  1. Stop all VMs
    docker-machine stop ${docker-machine ls -q}
    This step will release all assigned addresses to VirtualBox DHCP
  2. Start VMs in order
    docker-machine start vbox1 && docker-machine start vbox2 && docker-machine start vbox3
    This steps assign IP like this:
    192.168.99.100 : vbox1
    192.168.99.101 : vbox2
    192.168.99.102 : vbox3

Notice that docker-machine start vbox1 vbox2 vbox3 will not work, but I don't figure out why.

It's very useful.

@fernaspiazu
Copy link

fernaspiazu commented Jun 13, 2019

In order to assign a static ip address 192.168.99.50 to my docker-machine (default) on VirtualBox, I used:

$ echo -e "kill \`cat /var/run/udhcpc.eth1.pid\`\nifconfig eth1 192.168.99.50 netmask 255.255.255.0 broadcast 192.168.99.255 up" | docker-machine ssh default sudo tee /var/lib/boot2docker/bootsync.sh > /dev/null

$ docker-machine restart default
Restarting "default"...
(default) Check network to re-create if needed...
(default) Waiting for an IP...
Waiting for SSH to be available...
Detecting the provisioner...
Restarted machines may have new IP addresses. You may need to re-run the `docker-machine env` command.

$ docker-machine env
Error checking TLS connection: Error checking and/or regenerating the certs: There was an error validating certificates for host "192.168.99.50:2376": x509: certificate is valid for 192.168.99.103, not 192.168.99.50
You can attempt to regenerate them using 'docker-machine regenerate-certs [name]'.
Be advised that this will trigger a Docker daemon restart which might stop running containers.

$ docker-machine regenerate-certs default
Regenerate TLS machine certs?  Warning: this is irreversible. (y/n): y
Regenerating TLS certificates
Waiting for SSH to be available...
Detecting the provisioner...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...

$ docker-machine env
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.50:2376"
export DOCKER_CERT_PATH="/Users/mandrake/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell:
# eval $(docker-machine env)

My environment is OSX, VirtualBox (boot2docker.iso)

Hoping this can be useful 🙂
BTW: +1 for the new feature request 😉
Cheers.

@karaoguz-els
Copy link

Yes, there is an option to create with specific ip. All you need to do is specify ip/ip-range with
--virtualbox-hostonly-cidr option.

For example:

  • when you want to assign specific ip, let say you want to assign 10.15.1.24, then appropriate config will be (the most important thing is the mask that we are using here. For specific ip you need to set subnet mask to 32) :
    docker-machine create --driver virtualbox --virtualbox-hostonly-cidr "10.15.1.24/32" dev

  • if you want to pick an ip from specific ip range, then you need to use appropriate subnet mask.

@jandetlefsen
Copy link

If you issue is that you have to keep updating your host file you can just install Avahi on your container and use mDSN.

@mbishr
Copy link

mbishr commented May 16, 2021

It will be very useful to activate this feature to able to assign static ip address while creating vm using docker-machine

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests