Skip to content

Instantly share code, notes, and snippets.

@strayge
Created October 27, 2019 10:41
Show Gist options
  • Save strayge/481a77d31a94e133a76662877b1a90ca to your computer and use it in GitHub Desktop.
Save strayge/481a77d31a94e133a76662877b1a90ca to your computer and use it in GitHub Desktop.
windows 10, port reserved for HyperV

Error

docker windows bind: An attempt was made to access a socket in a way forbidden by its access permissions.

show reserved pool

netsh int ipv4 show excludedportrange protocol=tcp

undocumented key in registry

https://dandini.wordpress.com/2019/07/15/administered-port-exclusions-blocking-high-ports/

rem Modify Dynamic Port Range for Development Users
dism /online /get-features | find /i "Microsoft-Hyper-V" && (
rem Modify Dynamic Port Range
start /wait "" netsh int ipv4 set dynamicport tcp start=20000 num=16384
start /wait "" netsh int ipv4 set dynamicport udp start=20000 num=16384
rem Add Registry Key
start /wait "" reg add HKLM\SYSTEM\CurrentControlSet\Services\hns\State /v EnableExcludedPortRange /d 0 /f
goto :eof
)
rem Set range to default
start /wait "" netsh int ipv4 set dynamicport tcp start=49152 num=16384
start /wait "" netsh int ipv4 set dynamicport udp start=49152 num=16384
rem Remove Registry Key
start /wait "" reg delete HKLM\SYSTEM\CurrentControlSet\Services\hns\State /v EnableExcludedPortRange /f

another workaround

docker/for-win#3171 (comment)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment