creating "bridged" or "host-only" vm's with machine?
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.
+1
+1
+1
+1
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
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
@joeloria Adding a third bridged interface generally works. However, it breaks docker-machine config ... for me (version 0.5.4).
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.
@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.
+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.
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.
- Open the machine in Virtual Box and add a 3rd new
bridgenetwork. Do not modify the existing NAT or host network, this will break Docker. Do this when the machine is stopped (docker-machine stop default) - Start the machine backup -
docker-machine start default- You'll see an error that the machine has a new IP. - Run
eval "$(docker-machine env default)"you'll get an error that new certificates are required. - Run
docker-machine regenerate-certs defaultand select yes to confirm. - Run
docker-machine ip defaultand 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.
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
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.
+1 for simple, supported out-of-the-box methodology for LAN access to a running container
stop the docker machine and add another adaptor through the virtualbox works fine.
+1 bridged mode will be very helpful!
@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?
+1 for having bridged mode during "docker-machine create"
+1
+1 for bridged network.