Skip to main content
Code and think

Docker Troubleshoot issue with taken port

Sometimes when starting a Docker container on Windows and Hyper-V you can get an error that the port is unavailable:

ERROR: for container Cannot start service client: 
Ports are not available: listen tcp 0.0.0.0:XYZ: bind: 
An attempt was made to access a socket in a way 
forbidden by its access permissions.

In case, you cannot see the port being used by any of your local processes, check if Hyper-V is using it.

To do this, you can execute the command: netsh int ipv4 show excludedportrange protocol=tcp

To fix this one time, you can restart winnat: net stop winnat net start winnat

To fix it long term, you can exclude it from Hyper-V with the following command (run PowerShell as admin):

net stop winnat
netsh int ipv4 add excludedportrange protocol=tcp numberofports=1 startport=1433
net start winnat

Commonly used ports:

From Docker forum and Microsoft

Edit: previous answer required restart of the computer: dism.exe /Online /Disable-Feature:Microsoft-Hyper-V netsh int ipv4 add excludedportrange protocol=tcp startport=1433 numberofports=1 dism.exe /Online /Enable-Feature:Microsoft-Hyper-V /All