Reputation: 25349
docker run --rm -it -p 8080:80 mcr.microsoft.com/dotnet/core/runtime:3.1
docker run --rm -it -p 8080:80 mcr.microsoft.com/dotnet/core/sdk:3.1
docker run --rm -it -p 8080:80 mcr.microsoft.com/dotnet/core/aspnet:3.1
When I run any of the above docker commands to create a container, I get the following error. And I get this for both for linux as well as windows.
C:\Program Files\Docker\Docker\resources\bin\docker.exe: Error response from daemon: Ports are not available: listen tcp 0.0.0.0:8080: bind: An attempt was made to access a socket in a way forbidden by its access permissions. time="2020-03-24T17:20:44+05:30" level=error msg="error waiting for container: context canceled"
I tried the suggestion given in this SO ans to find the process Id and kill it.
Further I got the process hacker as suggested here to observe whats that process. Looks like its a system process.
Can anybody suggest what can be done?
Upvotes: 15
Views: 70428
Reputation: 509
I had a similar issue with my database port (Lando/Docker) on Windows. Running "net stop winnat" in PowerShell resolved it.
net stop winnat
Upvotes: 29
Reputation: 2823
Open PowerShell in administrator mode and enter the command
net stop http
The command lists (and gives you the option to stop) all services currently using port 80.
You can now start your docker container with port 80.
Upvotes: 0
Reputation: 21757
You can assign external port in the following ways:
EXPOSE 8080
docker -expose=8080 test
docker run --rm -it -p 8080:80 mcr.microsoft.com/dotnet/core/runtime:3.1
But you are allowed to do it only ONCE
Upvotes: 0
Reputation: 18980
This answer solves two errors I believe.
Error 1 (if the wrong port is specified in the Windows Defender Firewall for an existing rule for Docker):
Unable to find image 'docker102tutorial:latest' locally docker: Error response from daemon: pull access denied for docker102tutorial, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
Error 2 (if no Windows Defender Firewall rule at all and #:8080 is specified in docker run command in the -p parameter):
Error response from daemon: Ports are not available: listen tcp 0.0.0.0:8080: bind: An attempt was made to access a socket in a way forbidden by its access permissions.
In Windows 10, you will need to allow this through the Windows Defender Firewall. You'll get this dialog. You might be able to restrict the port for either the TCP by default (or UDP) line in the Windows Defender Firewall. The table screen shot of rules was taken before the port was modified and the last error was corrected. I believe the client in this case is WSL 2 and the server is Windows which means the incoming port needs to be opened on the server.
Allow Local Port 8080 in the Windows Defender Firewall so it matches the port after the ":" in the run command:
You will then get this error.
To correct, change from "Defer to user" to "Defer to application"
Upvotes: 1
Reputation: 1993
You assign the same host port 8080
multiple times, which is not allowed - on any operating system.
After running this command
docker run --rm -it -p 8080:80 mcr.microsoft.com/dotnet/core/runtime:3.1
the first container gets immediately the port 8080
assigned on the host machine, what we can also see in the console screenshot that you provided. And others fail, because they simply don't get the port they want. So that all containers can be started, you should use a different port for each container, a la
docker run --rm -it -p 8080:80 mcr.microsoft.com/dotnet/core/runtime:3.1
docker run --rm -it -p 8081:80 mcr.microsoft.com/dotnet/core/sdk:3.1
docker run --rm -it -p 8082:80 mcr.microsoft.com/dotnet/core/aspnet:3.1
You should then be able to access those containers via the respective ports 8080
, 8081
, and 8082
(on localhost
or local network IP of ur machine, e.g. 192.168.1.20
).
Upvotes: 4
Reputation: 3890
-p 8080:80
says "forward port 8080 on the host to port 80 in the container". Port 80 is determined by the container image. Port 8080 is arbitrary—it's a port you're choosing.
So instead do -p 8081:80
, and now you point your browser at localhost:8081 instead of localhost:8080.
If that doesn't work then maybe it's your firewall?
(See https://pythonspeed.com/articles/docker-connection-refused/ for diagrams of how port forwarding works).
Upvotes: 12