Windows container failed to start with error, "failed to create endpoint on network nat: HNS failed with error : Failed to create endpoint."

pinkal vansia picture pinkal vansia · Jun 28, 2016 · Viewed 13.8k times · Source

I have been trying Windows Containers on windows server 2016 TP5. Suddenly I started getting error while running a container with port maping option -p 80:80

c:\>docker run -it -p 80:80 microsoft/iis cmd
docker: Error response from daemon: failed to create endpoint sharp_brahmagupta on network nat: HNS failed with error : Failed to create endpoint.

I made sure that no other container is running and port 80 on host machine is not being used by any other service.

Did anyone face same issue?

Answer

pinkal vansia picture pinkal vansia · Jun 28, 2016

After searching around I stunbled upon this issue on github. This seemed to be a known issue with Windows containers on Windows server TP5.

Then thanks to this forum, I found the solution You can check active static port mapping with below command

C:\>powershell
PS C:\>Get-NetNatStaticMapping


StaticMappingID               : 3
NatName                       : Hda6caca4-06ec-4251-8a98-1fe0b4c5af88
Protocol                      : TCP
RemoteExternalIPAddressPrefix : 0.0.0.0/0
ExternalIPAddress             : 0.0.0.0
ExternalPort                  : 80
InternalIPAddress             : 172.31.181.4
InternalPort                  : 80
InternalRoutingDomainId       : {00000000-0000-0000-0000-000000000000}
Active                        : True

From above output it seemed that even though container was removed the static port mapping was not removed and was still active.

But I removed it with below command.

PS C:\> Get-NetNatStaticMapping | ? ExternalPort -eq 80 | Remove-NetNatStaticMapping

Then simply rebooted the system and the error was gone.