Repository navigation
Unable to bind ports: Docker-for-Windows & Hyper-V excluding but not using important port ranges #3171
Description
Activity
Solution in googlevr/gvr-unity-sdk#1002 works for me but not ideal
That workaround does not work for me, unfortunately, despite having admin rights.
@veqryn the workaround worked for me, the steps are:
-
Disable hyper-v (which will required a couple of restarts)
dism.exe /Online /Disable-Feature:Microsoft-Hyper-V -
When you finish all the required restarts, reserve the port you want so hyper-v doesn't reserve it back
netsh int ipv4 add excludedportrange protocol=tcp startport=50051 numberofports=1 -
Re-Enable hyper-V (which will require a couple of restart)
dism.exe /Online /Enable-Feature:Microsoft-Hyper-V /All
when your system is back, you will be able to bind to that port successfully.
Reacted by Ryo Utsunomiya, Stanislav Dontsov, handaya, Aaron Havens, Jerwin, glwlg, Shinji Takenaka, Bruce Sun, Wyatt Fry, Michael Ledin and 205 moreReacted by Zheyuan Zhou, jforge, Ryan Crosby, Zhu yuhan, Philip Empl, Oussama Bouguerne, current1990, Arda Develioglu, StudysoHard, 无常 and 2 moreReacted by Alexandre Pires, NguyenTheAnh, strarsis, Locher, Charles Mendes de Macedo, SergeySetti, Wes Doyle, alexW3design, Jacob Shilitz, barryzhan2017 and 21 moreReacted by Alexandre Gagner, Victor Alves, Anton Pegov, Itay Podhajcer, Yohan Belval, Paul PRIKAZSKY, Jacob Shilitz, IronSpecs, tshavkat, Julien Ricard and 21 moreReacted by Alexandru Dodu, 0x5756647361316c584e413d3d, Jonathan Mohrbacher, Oleh Borysenko, Peter McNeely, Adam Kiss, strarsis, Locher, GoodDok, Tarik Guney and 30 moreReacted by Tarik Guney, Sandra Ahlgrimm, SergeySetti, Jacob Shilitz, barryzhan2017, AChao, Ciaran Liedeman, agneisilva, Lalit Gangwar, Raul Villora Valencia and 12 moreReacted by Sadeq Sardari, ailihp, Jacob Shilitz, barryzhan2017, Michael Sanford, wooocare, jforge, Philip Empl, 无常, James Keller and 2 more-
- added a commit that references this issue
on Apr 4, 2019 Issues go stale after 90d of inactivity.
Mark the issue as fresh with/remove-lifecycle stalecomment.
Stale issues will be closed after an additional 30d of inactivity.Prevent issues from auto-closing with an
/lifecycle frozencomment.If this issue is safe to close now please do so.
Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows.
/lifecycle stale/remove-lifecycle stale
- added a commit that references this issue
on May 21, 2019 What's the status for this?
Today I had 100 of reservations which caused Skype for Business to stop working since it couldn't find any available ports. Uninstall docker/hyper-v/containers removed these reservations and Skype for Business had ports to work with again.
This is a critical error that should be focused on since it reserves so many ports that isn't in use. I can't uninstall docker/hyper-v/containers or similar workarounds each time I get problems with Skype for Business in conjunction with meetings.
Reacted by 9Rune5, Matt LaPaglia, Juan Antonio, Markus Schuh, Marius Johansen, Jonathan Wilbur, Daniele Demichelis, Leroy14, Zachary Kruse, slothmotion and 38 moreThis makes hyper-v unusable for me and most of my company.
Reacted by Michael Sanford, Andrea Vouk, Benito PS, brad-tilmor, Theo Diefenthal, J Khalaf, TrustworthySystems, Sadiinso, TheAloneShadow and tralalalolo@enashed Does your solution (disabling and re-enabling HyperV) have any side effects? Will my virtual switches and virtual machines still be there after applying your solution?
Answering myself: This actually does have side effects. It deletes your virtual switches. You should keep that in mind when applying this solution.
Reacted by Jonathan Wilbur, Chris Modjeska, Jon Goodger, Victor Alves, Monte Christo, Michael Sanford, Kubis Fowler, Benito PS, Timlukas Bloch, Piotr Karkut and 6 moreReacted by Michael Sanford, Timlukas Bloch, belgacea, Anas AIT BAHA, dymo, TrustworthySystems, Piotr Karkut and Sadiinsothis issue is still present
/remove-lifecycle staleReacted by strarsis, Daniele Demichelis, Leroy14, Zachary Kruse, Tim Yorke, Victor Alves, Daniel Genezini, Zeno Jiricek and Björn MichaelHi guys, I've the same problem. This is really blocking me.
Reacted by Daeun Kim, Tim Yorke, bielitom, Yesid Bocanegra, Joshua Semar, Zachary Kruse, Leroy14, Chris Duncan, Victor Alves, Daniel Genezini and 14 more94 remaining items
but after that, i don't have access to internet in wsl.
Weird, it worked for me? I havent had the problem since but I'll try and verify when it pops up again.
Reacted by Amir and Michał PanasiewiczHow is this still not solved.... very frustrating problem.
but after that, i don't have access to internet in wsl.
I'm having the same issue. But sometimes it says "The service is starting or stopping. Please try again later" after I run "net stop winnat", then I can't make it start again, and I get stuck there. :(
Reacted by Benjamin LevesqueStill encouner this bug from time to time,
Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:9000 -> 0.0.0.0:0: listen tcp 0.0.0.0:9000: bind: An attempt was made to access a socket in a way forbidden by its access permissions.
but following this can fix it:
SOLUTION: The right solution TLDR version
The correct solution is simply to reset the “TCP Dynamic Port Range” so that Hyper-V only reserves ports in the range we have set. You can reset the “TCP Dynamic Port Range” to 49152–65535 by running the following command with administrator privileges, but you can also change it to a smaller range if you think it is too large.
netsh int ipv4 set dynamic tcp start=49152 num=16384 netsh int ipv6 set dynamic tcp start=49152 num=16384The article discusses a problem encountered while using Docker. The issue involves ports of Docker containers not working, leading to a common error related to access permissions. The root cause is attributed to the "TCP dynamic port range" in Windows, with potential conflicts arising from Hyper-V's reserved port numbers.
The article acknowledges that while stopping and starting the Winnat service may offer a temporary solution, it explicitly states that this method is essentially a simplified version of rebooting the computer. The author points out that relying on this approach may not guarantee a resolution, as the probability of success is random, with some users reporting it works while others say it doesn't. The article strongly recommends against this method as a reliable or optimal solution due to its unpredictable nature.
Reacted by sampenguin, Eric To, Steven Bock, inasayang, w-, Zettroke, Mocha, Ran Hum, shannon and kazenorinReacted by Yorai Levi, Maciej Holyszko, JP, TK9798, Steven Bock, Christoph Rackwitz, Mocha and shannon- added a commit that references this issue
on Sep 15, 2025 - added 2 commits that reference this issue
on Mar 26, 2026 - added a commit that references this issue
on Apr 27, 2026 - added a commit that references this issue
on Jun 25, 2026 - added a commit that references this issue
on Jul 26, 2026 Docker says the port is taken, but no program is listening. Windows often reserved that port for itself.
Check:
netsh interface ipv4 show excludedportrange protocol=tcpIf your port is on that list, the WinNAT service is holding it. Give it back:
net stop winnat
net start winnatIf your port is not on that list, this will not help. Something else really has the port.
BB0297BB-C287-4F0B-A007-72B5F2D7BD72/20190102235413Expected behavior
Be able to bind specific ports that I have always used.
Be able to specify which ports docker/hyperv exclude or use, and/or I expect that docker/hyper-v actually use the ports that it is excluding and that they show up in
netstat -anoas being used or listened on.Actual behavior
If I start a service that binds on port 50051 (it is a grpc service, and that is the traditional port used by grpc), it says:
listen tcp :50051: bind: An attempt was made to access a socket in a way forbidden by its access permissions.Information
Steps to reproduce the behavior
My own investigation:
I was extremely confused by this problem, because I was able to bind other ports, such as 8080 or 60000, yet it did not appear that 50051 was in use by anything on my system.
Running
netstat -anoshows nothing using 50051.Running
Get-NetTCPConnectionin powershell with admin privileges shows nothing using 50051.Even if I disconnect from the internet and disable both windows firewall and my antivirus, and run everything as admin, I still get the errors.
After hours of google searching, I found a command that showed what happened to 50051:
It seems that 50051 is excluded (whatever that means?!), even though it isn't in use by anything.
After lots of trial and error, I discovered that Docker for Windows and Hyper-V are responsible for all of those excluded port ranges above.
It also seems like all those port ranges change or increase by 1 every time I reboot, so I suppose 450 reboots from now my problem will go away, maybe...
I have never had this problem, despite using docker for years now.
I run lots of containers and setups that other people at my company work on and rely on, so it is not feasible for me to be changing the ports around on them to work around this issue. (Other people use the kube templates and docker-compose, and some of them connect with other docker-compose networks, etc, and expect things on certain ports.)
When I try to delete that excluded port range, I get this, despite running the command as administrator: