Ports are not available: listen tcp 0.0.0.0/50070: bind: An attempt was made to access a socket in a way forbidden by its access permissions

DockerHadoopPortDocker Image

Docker Problem Overview


I am trying to start a docker container with the below command.

docker run -it -p 50070:50070 -p 8088:8088 -p 8080:8080 suhothayan/hadoop-spark-pig-hive:2.9.2 bash

It ended up with the following error.

> docker: error response from daemon: Ports are not available: listen tcp 0.0.0.0/50070: bind: An attempt was made to access a socket in a way forbidden by its access permissions.

As I understand, the error has occurred as the port 50070 is used by another process. I've tried to identify the process in order to kill that with the below command in the command prompt, but it does not give an output nor an error.

netstat -ano | findstr :50080

Docker Solutions


Solution 1 - Docker

This solution helped me:

net stop winnat
docker start container_name
net start winnat

Solution 2 - Docker

I did this to stop tcp processes =>

  • net stop winnat
  • net start winnat

In this way, the busy port operation is terminated.

This worked for me.

Solution 3 - Docker

As per Docker issue for windows https://github.com/docker/for-win/issues/3171 :

You might have that port in any of the excluded port ranges of command netsh interface ipv4 show excludedportrange protocol=tcp

You can use solution mentioned in the above ticket.

  1. Disable hyper-v (which will required a couple of restarts)

    dism.exe /Online /Disable-Feature:Microsoft-Hyper-V

  2. After finishing 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=50070 numberofports=1

  3. Re-Enable hyper-V (which will require a couple of restart)

    dism.exe /Online /Enable-Feature:Microsoft-Hyper-V /All

Solution 4 - Docker

On my local machine had similar issue with Docker Desktop and integration enabled with Debian/Ubuntu set as default distro (WSL2 as standard to all). How I solved:

  • Docker settings disabled "Start Docker Desktop when you log in"
  • Restarting Windows
  • First starting Debian/Ubuntu
  • Then start Docker Desktop

Solution 5 - Docker

I faced with this situation when my VPN connection is active.
you can temporarily disconnect your VPN connection, after that start your docker container, and go back and connect to your VPN again

Solution 6 - Docker

Restarting winnat is not a good idea, the root cause is that some ports of windows are dynamically reserved, even though they are not occupied.This command can be used to solve.

netsh int ipv4 set dynamic tcp start=49152 num=16384
netsh int ipv6 set dynamic tcp start=49152 num=16384

This article explains it in detail, and I recommend taking a look at it.

Completely solve the problem of docker containers running on Windows 10 due to port binding

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionlse23View Question on Stackoverflow
Solution 1 - DockerCepr0View Answer on Stackoverflow
Solution 2 - DockerGöktuğ YıldırımView Answer on Stackoverflow
Solution 3 - DockerSandeepView Answer on Stackoverflow
Solution 4 - DockerGui.M.View Answer on Stackoverflow
Solution 5 - DockerAmirHossein AbdolmotallebiView Answer on Stackoverflow
Solution 6 - DockerEcholdmanView Answer on Stackoverflow