machine icon indicating copy to clipboard operation
machine copied to clipboard

creating "bridged" or "host-only" vm's with machine?

Open myfear opened this issue 11 years ago • 67 comments

I was wondering, if anybody can point me to an instruction how to create a vm with either a bridged or a host-only eth0 NIC on the host.

Creating a standard machine with "docker-machine create --driver virtualbox mymachine" and changing Adapter 1 to bridged or host-only doesn't work afterwards. (Which totally makes sense to me).

In some scenarios, I'd actually love to have the docker machine vm accessible by IP address (and not only port forwarding) from my windows 7 host.

--virtualbox-hostonly-cidr only affects the inter container Adapter 2 AFAIK.

myfear avatar Jul 08 '15 10:07 myfear

+1

yangboz avatar Dec 14 '15 13:12 yangboz

+1

ghost avatar Dec 16 '15 18:12 ghost

+1

joeloria avatar Dec 22 '15 19:12 joeloria

+1

dhval avatar Dec 23 '15 21:12 dhval

So I was able to get this working

I was messing around with the virtualbox vm and i had two networks setup

Adapter 1 - NAT Adapter 2 - vboxnet1

Docker deamon needs NAT mode to be able to communicate with the vm so changing that to bridge breaks it. What i did was i stopped the vm (docker-machine stop xxxx) brought up virtualbox and created a 3rd adapter with bridge and started the vm (docker-machine start xxxx) and then (docker-machine ip xxx) will give you a network ip you can use.

you should be able to use the command line to do it as well but I went via the app

joeloria avatar Dec 23 '15 21:12 joeloria

If you'd like the machine, and thus your containers, to be able to use the host machine's DNS interface, stop the machine and then run:

VBoxManage modifyvm $MACHINE_NAME --natdnshostresolver1 on

Start the machine afterwards and you should be good to go without a bridge network.

cc: @drawsmcgraw

mattupstate avatar Jan 01 '16 18:01 mattupstate

@joeloria Adding a third bridged interface generally works. However, it breaks docker-machine config ... for me (version 0.5.4).

deas avatar Jan 14 '16 11:01 deas

Thanks @mattupstate ! Can I do this without having to create the third network interface like @joeloria did? That would be more elegant than my current technique, which is giving hard-coded DNS servers to the VM when I create it.

Looks like it's a permanent thing, too, going by the docs.

drawsmcgraw avatar Jan 14 '16 12:01 drawsmcgraw

@mattupstate @drawsmcgraw @deas It's worth noting as well that these DNS options are now available to set at create time using --virtualbox-host-dns-resolver and --virtualbox-dns-proxy.

In our experience setting them to on and off both have tradeoffs, so it's up to you to decide what's right for your use case.

nathanleclaire avatar Jan 14 '16 23:01 nathanleclaire

+1. this would make a lot easier for instance to run an FTP docker image that uses a lot of port mappings in case of NATted configuration.

rantoniuk avatar Jan 15 '16 18:01 rantoniuk

I've had some success running the machine on a bridged network when setup manually. However the machine will often end up corrupted if I roam my machine to a new network. But it works as long as you stay on the same network. In this example, I'm using the default machine name default.

  1. Open the machine in Virtual Box and add a 3rd new bridge network. Do not modify the existing NAT or host network, this will break Docker. Do this when the machine is stopped (docker-machine stop default)
  2. Start the machine backup - docker-machine start default - You'll see an error that the machine has a new IP.
  3. Run eval "$(docker-machine env default)" you'll get an error that new certificates are required.
  4. Run docker-machine regenerate-certs default and select yes to confirm.
  5. Run docker-machine ip default and you'll see the machine is now running on the LAN network. Other machines on the LAN can now access exposed ports on this machine.

+1 that it would be nice for the default machine to be created on bridge by default, or configurable somehow. I've not found a command line option to create the machine using the bridge network.

samkelleher avatar Jan 17 '16 13:01 samkelleher

expanding on samkelleher's above - with a VirtualBox command (VBoxManage) to create the 3rd new bridged interface. I'm using dinghy which is a wrapper for docker-machine. just replace the dinghy commands with docker-machine. (my docker-machine name is 'dinghy')

dinghy destroy

dinghy create --provider virtualbox --memory 512
docker-machine stop dinghy
VBoxManage list bridgedifs
VBoxManage modifyvm dinghy --nic3 bridged --bridgeadapter3 en0
docker-machine start dinghy

docker-machine regenerate-certs dinghy
eval "$(docker-machine env dinghy)"

docker-machine ls

roocell avatar Jan 30 '16 20:01 roocell

We had the use case that we wanted to access our developer machines running docker in VirtualBox machines with external devices (e.g. smartphones, tablets) and found the easiest way is to expose the docker machine via a bridged network.

We use the following script, that adds the bridged network adapter and prints the external IP: https://github.com/blueimp/shell-scripts/blob/df2eaf79ad7935bfb4b6d5834895d4912d6df4ea/bin/docker-machine-bridge.sh

In our tests, this does not require a regeneration of certs, as docker still uses the host-only networking to communicate with the machine.

The alternative would be to use the port forwarding feature of VirtualBox, although that requires the external ports to be higher than 1024 unless VirtualBox is run as root, e.g.:

VBoxManage modifyvm default --natpf1 'http,tcp,,8080,,80'
VBoxManage modifyvm default --natpf1 'https,tcp,,8443,,443'

In addition to the docker machine bridge script mentioned above, we also make use of a simple script to start a dnsmasq container, resolving the project hostnames to the bridged IP of the docker-machine: https://github.com/blueimp/shell-scripts/blob/df2eaf79ad7935bfb4b6d5834895d4912d6df4ea/bin/dns.sh

This allows us to simply enter the IP of the bridged docker machine as DNS server in the settings of any smartphone, tablet or other device and then access the developer machine via the configured project hostnames.

The setup on a developer box running docker-machine is simply the following:

./bin/dns.sh $(./bin/docker-machine-bridge.sh)

This works as the docker machine bridge script prints the bridged IP to STDOUT.

blueimp avatar Feb 05 '16 14:02 blueimp

+1 for simple, supported out-of-the-box methodology for LAN access to a running container

dbbernstein avatar Mar 18 '16 17:03 dbbernstein

stop the docker machine and add another adaptor through the virtualbox works fine.

jalenyang avatar Mar 22 '16 09:03 jalenyang

+1 bridged mode will be very helpful!

xbeta avatar Mar 23 '16 03:03 xbeta

@joeloria solution seems best, why should the docker machine team need to add this feature when this is just a 'nice-to-have' for local development?

camsjams avatar Apr 11 '16 03:04 camsjams

+1 for having bridged mode during "docker-machine create"

apannwitz avatar Apr 19 '16 15:04 apannwitz

+1

davidenke avatar Apr 20 '16 08:04 davidenke

+1 for bridged network.

f-w avatar Apr 20 '16 22:04 f-w