When using the new Docker for Windows, vpnkit is used to automatically forward ports from localhost to the containers running in the Hyper-V VM:
https://github.com/moby/vpnkit/blob/master/docs/ports.md
This means it's possible to connect to services on eg: localhost:8000
(like is possible when the Docker host OS is Linux) rather than $(docker-machine ip):8000
. This is which is more convenient, since:
localhost
), so requires workarounds to either get the IP into the container (eg for Django ALLOWED_HOSTS
) or else manual updates to C:\Windows\System32\Drivers\etc\hosts
(until we have #1792).However when using Docker Machine with boot2docker (that uses Virtualbox rather than Hyper-V), port forwarding isn't automatically set up - so users have to do so manually using:
VBoxManage modifyvm "VM name" --natpf1 "tcp-port8000,tcp,127.0.0.1,8000,,8000"
(if the machine is powered down)VBoxManage controlvm "VM name" --natpf1 "tcp-port8000,tcp,127.0.0.1,8000,,8000"
(if the machine is running)As such, it would be great if Docker Machine / the Docker daemon / vpnkit automatically ran the controlvm command when containers that declared ports were started.
(Ideally I would use the new Docker for Windows, however doing so isn't very practical yet, since it requires Hyper-V which prevents all other Virtualbox VMs from working, and so would require continual reboots when switching between projects that use Docker and eg Vagrant with Virtualbox.)
if a controlvm not a modifyvm, remove the hypen. otherwize it errors with invalid parameter.
- VBoxManage controlvm "VM name" --natpf1 "tcp-port8000,tcp,127.0.0.1,8000,,8000"
+ VBoxManage controlvm "VM name" natpf1 "tcp-port8000,tcp,127.0.0.1,8000,,8000"
reference: https://www.virtualbox.org/ticket/10122#comment:2
Most helpful comment
if a controlvm not a modifyvm, remove the hypen. otherwize it errors with invalid parameter.
reference: https://www.virtualbox.org/ticket/10122#comment:2