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

后端 未结 4 936
你的背包
你的背包 2021-01-12 06:01

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

相关标签:
4条回答
  • 2021-01-12 06:29

    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!

    0 讨论(0)
  • 2021-01-12 06:35

    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
    
    0 讨论(0)
  • 2021-01-12 06:41

    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.

    0 讨论(0)
  • 2021-01-12 06:46

    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)

    0 讨论(0)
提交回复
热议问题