Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 666
pinkal vansia Avatar asked Jun 28 '16 08:06

pinkal vansia


3 Answers

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.

like image 123
pinkal vansia Avatar answered Oct 21 '22 04:10

pinkal vansia


For me these steps solved the problem:

Stop-Service docker
Get-ContainerNetwork | Remove-ContainerNetwork
Get-NetNat | Remove-NetNat
Get-VMSwitch | Remove-VMSwitch
Start-Service docker

(suggested by JMesser81 at:https://github.com/Microsoft/Virtualization-Documentation/issues/273)

like image 25
HamedH Avatar answered Oct 21 '22 05:10

HamedH


I had similar error.

$ docker --version
Docker version 1.13.0-rc3, build 4d92237
$ docker-compose -f .\docker-compose.windows.yml up
Starting musicstore_db_1

ERROR: for db  Cannot start service db: {"message":"failed to create endpoint musicstore_db_1 on network nat: HNS failed with error : Unspecified error"}
ERROR: Encountered errors while bringing up the project.

Static mapping removal did not work, only network removal helped:

Get-ContainerNetwork -Name nat | Remove-ContainerNetwork

Execute the command in PowerShell as administrator, then restart Docker.


Update:

Use CleanupContainerHostNetworking.ps1 script to resolve Docker 17 networking issues.

.\CleanupContainerHostNetworking.ps1 -Cleanup -ForceDeleteAllSwitches
like image 32
Der_Meister Avatar answered Oct 21 '22 05:10

Der_Meister