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

4

9

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?

Becquerel answered 28/6, 2016 at 8:23 Comment(0)
B
12

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.

Becquerel answered 28/6, 2016 at 8:28 Comment(0)
F
9

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)

Fornication answered 22/12, 2016 at 13:42 Comment(0)
G
6

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
Ginelle answered 14/12, 2016 at 10:51 Comment(0)
S
0

I had a docker and docker-compose which were already working on Centos. I did the following changes to make it work on windows server 2016:

  1. Stop the docker service, remove nat, start the docker service.

    ps>stop-service docker
    ps>Get-ContainerNetwork | Remove-ContainerNetwork -Force -ea SilentlyContinue
    ps>start-service docker   
    
  2. Configure network in your docker-compose.yml

    version: '3.7'
    networks:
      default:
        external:
          name: nat    
    

That's It!

Stinkhorn answered 6/2, 2019 at 9:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.