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
Asked Answered
S

13

123

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
Senaidasenalda answered 13/12, 2020 at 5:53 Comment(1)
Does this answer your question? An attempt was made to access a socket in a way forbidden by its access permissionsHetero
B
53

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

Betweentimes answered 13/12, 2020 at 9:25 Comment(0)
B
309

This solution helped me (run as administrator your terminal):

net stop winnat
docker start container_name
net start winnat
Bodine answered 14/2, 2021 at 18:17 Comment(3)
This doesn't explain why things fail.Attorney
Thanks it helped me. I was facing the same error, I ran the first command (net stop winnat) in administrator mode of windows powershell then, I ran (docker-compose up --build -d) and at the end I ran the last command(net start winnat).Goebbels
Hit this problem for the first time (despite having used this container many times) today on my Windows 11 machine (23H2, 22631.2199). This fix worked, thank you.Gaudette
I
105

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.

Inferential answered 4/6, 2021 at 20:41 Comment(2)
Thank you! This one worked for me in Windows 10.Taejon
thanks! worked for me too, not sure why thoughGutta
B
53

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

Betweentimes answered 13/12, 2020 at 9:25 Comment(0)
P
13

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

Parasynapsis answered 10/5, 2022 at 13:34 Comment(1)
The link really helped explain and seems like the most appropriate way to solve the problem. Disabling Hyper-V seems like overkill and extra restarts.Willawillabella
M
4

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

Mikes answered 4/12, 2021 at 10:41 Comment(0)
M
4
  1. run net stop winnat
  2. If you use docker desktop, just run the container. Otherwise run this command in command prompt: docker start <container_name>
  3. run net start winnat
Mchenry answered 5/1, 2023 at 10:11 Comment(0)
T
2

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
Tropophilous answered 9/4, 2021 at 13:42 Comment(0)
K
2

Try restarting "Host Network Service"

Kenwee answered 19/5, 2022 at 1:32 Comment(0)
F
2

This is often caused by the Windows NAT Driver (winnat), stopping and restarting that service may resolve the issue.

open shell as administrator, and types those commands:

  1. net stop winnat.
  2. docker start ...
  3. net start winnat
Fingertip answered 4/6, 2022 at 13:21 Comment(2)
This answer had already been provided by Cepr0 last year.Indigestible
I like both answers, the main thing is that you need to restart the winnat service, and after that it will work like it's intended to.Taejon
L
1

I had to disable Windows IIS:

  • Call Control Panel > Programs and Features Click Turn Windows features on or off Scroll down to Internet Information Services

enter image description here

  • Click on the square next to Internet Information Services so it becomes empty

enter image description here

  • Click OK and reboot if required.

See https://superuser.com/questions/1377068/how-do-i-disable-the-iis-server-on-windows-10-and-free-up-port-80

Also, I had to enable Hyper-V along with Virtual Machine Platform and Windows Hypervisor Platform:

enter image description here

Lymphangial answered 13/5, 2023 at 13:15 Comment(0)
W
1
  1. Open your docker-compose.yaml file.
  2. Locate the service definition where the port conflict is happening.
  3. In that service, leave the HOST_PORT empty. This will allow Docker to dynamically generate a port every time your container starts.

For instance,

ports:
  -5672:5672
  -15672:15672

Do it:

ports:
  - :5672
  - :15672

You can check the dynamically assigned port through Docker Desktop or by running docker-compose ps.

Weathercock answered 14/10, 2023 at 11:5 Comment(0)
A
0
***net stop winnat
docker start container_name
net start winnat***

writing this in cmd worked well for me, thank you so much commentators for the solution.

Aphrodite answered 1/9, 2022 at 15:43 Comment(0)
A
0

I've run into this issue numerous times exposing ports with Docker, VS Code, etc.

Here's some Powershell that helps me determine the PID that's listening on the port and causing the conflict:

$LOCALPORT = "8000"
$CONNECTIONS = Get-NetTCPConnection -State Listen |Select-Object -Property LocalPort, State, @{name='ProcessID';expression={(Get-Process -Id $_.OwningProcess). ID}}, @{name='ProcessName';expression={(Get-Process -Id $_.OwningProcess). Path}}
Foreach ($I in $CONNECTIONS)
{
  If ($I.LocalPort -eq $LOCALPORT)
  {
    $I.ProcessID
  }
}

Change $LOCALPORT to whatever port is in use.

You can then inspect that process further, or stop it and the port should be freed up:

Stop-Process -Id 12345

Hopefully this snippet helps someone.

-Lucas

Arthro answered 12/4 at 23:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.