-
Notifications
You must be signed in to change notification settings - Fork 21
Flancy in a Windows Container
This article was tested with Windows Server 2016 CTP 4
Install a Windows Server 2016 into a hyper-v guest or on bare metal. Ensure that it has network connectivity and is joined to a domain. Once this is completed, perform the following steps:
Add-WindowsFeature containersAdd-WindowsFeature routing- Run the container script from Microsoft found here
The container script will create a vswitch for your host and container to communicate through, and it will download a copy of the base server core container to your host.
You can validate that this worked by calling Get-ContainerImage. If the script works, you should see the following:
[server5]: PS C:\> Get-ContainerImage
Name Publisher Version IsOSImage
---- --------- ------- ---------
WindowsServerCore CN=Microsoft 10.0.10514.0 TrueAlso, Get-VMSwitch should show a switch named "Virtual Switch":
[server5]: PS C:\> Get-VMSwitch
Name SwitchType NetAdapterInterfaceDescription
---- ---------- ------------------------------
Virtual Switch NATRun the following to create a container and shell into it as admin:
$img = Get-ContainerImage WindowsServerCore
$container = New-Container -Name "FlancyContainer" -ContainerImage $img -SwitchName "Virtual Switch"
$container |Start-Container
Enter-PSSession -ContainerID $container.ContainerID -RunAsAdministratorFor this example, we'll use the default settings of New-Flancy. This will serve a hello world! string from http://localhost:8000. However, we'll be using the public switch to allow it to receive requests from external sources on any IP address or hostname.
wget -uri https://github.com/toenuff/flancy/archive/master.zip -outfile c:\flancy.zip
unblock-file c:\flancy.zip
Expand-Archive C:\flancy.zip c:\
mv c:\flancy-master c:\flancy
Import-Module c:\flancy\flancy.psd1
New-Flancy -Public
Invoke-RestMethod http://localhost:8000 # This should spit out "Hello World!"Finally, grab the IP address of the container
[server5]: [5431449e-0b6]: PS C:\> Get-NetIPAddress -InterfaceAlias vEthernet* -AddressFamily ipv4 |select -ExpandProperty ipaddress
172.16.0.2First, ensure that you can reach your flancy app from the host (not inside the container) using the IP address grabbed at the end of Part III above:
[server5]: PS C:\> Invoke-RestMethod http://172.16.0.2:8000
Hello World!As long as you can see the "Hello World!" output, you can now set up the NAT between the host and the container. This is done by running the following netsh in the Container Host (not in the container):
netsh interface portproxy add v4tov4 listenport=8888 connectaddress=172.16.0.2 connectport=8000 protocol=tcpAssuming my container host is named server5 (which it is), I can now connect to http://server5:8888 from any computer on my network. It will be rerouted to 172.16.0.2:8000 which is running in the container.
- Need to test the above - I turned the firewall off at one point - may need to just add a specific rule at some point rather than disable the entire firewall.
- Need to figure out how we get apps to start automatically in a container and add to the documentation
- Need to show how to save your container app as a container image after it is configured so that it can be transported to other hosts and used.