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!

amoussa78 commented 6 years ago

+1

maciekkreft commented 6 years ago

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 commented 6 years ago

+1

fcying commented 5 years ago

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 commented 5 years ago

This functionality has been added to Minishift spome time ago, but it needs a modification to the ISO to function. On Hyper-V we ran into issues that the boot2docker image does not played nicely... so it only worked on CentOS and Fedora based images. Also, this does not work with the current KVM driver as it relies on DHCP.

This would need a slight redesign...

On Sun, Feb 3, 2019 at 11:08 PM fcying notifications@github.com wrote:

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.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

--

Gerard Braad | http://gbraad.nl [ Doing Open Source Matters ]

arikw commented 5 years ago

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 commented 5 years ago

👍

wontheone1 commented 5 years ago

It would really make my life easier.

burtsevyg commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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:

jandetlefsen commented 4 years ago

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 commented 3 years ago

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