With Windows Server 2016, containers are coming as a new feature in Windows Server. With the TP5, the managing of containers has changed. In fact, to manage network, you don’t need a new switch anymore, but we use the new PowerShell CmdLet New-ContainerNetwork. To add a NAT rule, you need to use the Add-ContainerNetworkAdapterStaticMapping command. So I executed this:
$iiscore = Get-Container -Name $containerNameIIS
Add-ContainerNetworkAdapterStaticMapping -Container $iisCore -AdapterName "$containerNameIIS-NetAda" -ExternalPort 80 -InternalPort 80 -Protocol TCP
But I had the following error:
Add-ContainerNetworkAdapterStaticMapping : The operation failed.
After looking during some minutes, I tried to stop the container and to execute the command again. And this time it works fine:
I verified that the NAT rule has been created correctly:
Conclusion: You MUST stop the container that you want to modify (for the network) to execute the command without error.