Welcome to weblogs.com.pk Sign in | Join | Help

Docker on Windows: HyperV, NAT and DHCP Server

Docker on Windows

In the first part, Docker on Windows, we created an Internal Switch in HyperV and shared the external interface so that our Docker VM gets a fixed known IP as well as have internet connectivity. This arrangement might not work all the time; Internet Connection Sharing (ICS) tends to assign the IPs of its own choice and if we want to switch from Wifi to Ethernet for internet connectivity (laptop scenario) it becomes messy. If you are using Windows 10 / 2016 HyperV; we can avoid ICS setup and instead use newly introduced HyperV Interface type NAT. This allow us to have internal ip subnet of our choice for our VMs (Docker VM) and traffic from VMs connected to this interface will get NATed and VMs will have internet connectivity. We can expose the port / service running on VMs externally as well. Open up an Administrative Power Shell and execute the following commands

> New-VMSwitch –Name “NAT” –SwitchType NAT –NATSubnetAddress 192.168.10.0/24
> New-NetNAT –Name “NAT” –InternalIpInterfaceAddressPrefix “192.168.10.0/24”

image

  • “NAT” is the name of the switch
  • 192.168.10.0/24 is the subnet of our choice; it will automatically give 192.168.10.1 IP to the interface that we can use as a gateway for VMs connected to NAT switch

The NAT switch will appear as “Internal” in HyperV’s visual interfaces

image

We used Boot2Docker for setting up the VM for Docker; it need a DHCP server on the internal network; sadly HyperV networking doesn't have such arrangement out of the box, if your host OS is server you can setup DHCP services, but if you are using client OS i-e Windows 10 you will need either a separate VM acting as DHCP server (Linux Core or something like that) or some third party light weight DHCP server application like http://dhcpserver.de that you can run on the guest OS

  • dhcpserver.de has dhcpwiz.exe a wizard that let you create dhcpsrv.ini and dhcpsrv.exe that you can run as system tray application or as Windows Service
  • Dont forget to add the Firewall Rule that wizard let you create in the last step
  • You can add static ip binding to mac address in the ini file like shown below

image

With this arrangement in place; you can have the known static ip of your choice and Boot2Docker will get it from dhcpserver. You might need to regenerate the certificate once this new setup is in place

Reference

Published Saturday, June 11, 2016 3:05 PM by khurram

Comments

No Comments

New Comments to this post are disabled