[Container] Error when you try to add a static mapping rule

June 3, 2016 at 6:00 am in Container, Microsoft, Windows Server 2016 by Florent

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.

image

After looking during some minutes, I tried to stop the container and to execute the command again. And this time it works fine:

image

I verified that the NAT rule has been created correctly:

image

Conclusion: You MUST stop the container that you want to modify (for the network) to execute the command without error.