Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Port issue with Docker for Windows

Tags:

docker

I'm trying to follow the beginner tutorial at training.play-with-docker.com. At Task 2, step 6, I do the following and get the error as below:

PS C:\Users\david.zemens\Source\Repos\linux_tweet_app> docker container run --detach --publish 80:80 --name linux_tweet_app $DOCKERID/linux_tweet_app:1.0
d39667ed1deafc382890f312507ae535c3ab2804907d4ae495caaed1f9c2b2e1
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: driver failed programming external connectivity on endpoint linux_tweet_app (a819223be5469f4e727daefaff3e82eb68eb0674e4a46ee1a32e703ce4bd384d): Error starting userland proxy: listen tcp 0.0.0.0:80: bind: An attempt was made to access a socket in a way forbidden by its access permissions.

I am using Docker Desktop on a Win10 machine locally. I've tried resetting Docker as suggested here. Error persists. Since something else must be using port 80, I should be able to avoid the error by using a different port, right?

PS C:\Users\david.zemens\Source\Repos\linux_tweet_app> docker container run --detach --publish 1337:1337 --name linux_tweet_app $DOCKERID/linux_tweet_app:1.0

Right! docker ps now confirms the container is running:

CONTAINER ID        IMAGE                         COMMAND                  CREATED              STATUS              PORTS                                     NAMES
b700df12c2d1        dzemens/linux_tweet_app:1.0   "nginx -g 'daemon of…"   About a minute ago   Up About a minute   80/tcp, 443/tcp, 0.0.0.0:1337->1337/tcp   linux_tweet_app

But when I try to view the webpage that the tutorial sends me to, I get an error in the browser.

enter image description here

I'm not sure how the link is dynamically generated but it looks something like this:

http://ip172-18-0-32-blsfgt2d7o0g00epuqi0-80.direct.labs.play-with-docker.com/

Browser error as below:

The proxy could not connect to the destination in time.
URL: http://ip172-18-0-32-blsfgt2d7o0g00epuqi0-80.direct.labs.play-with-docker.com/
Failure Description: :errno: 104 - 'Connection reset by peer' on socketfd -1:server state 7:state 9:Application response 502 cannotconnect

Another highly-upvoted answer suggests I need to "disable Windows 10 fast startup" -- I have not tried this yet, mainly because I'm not sure what the full repercussions are with that setting.

Is there something stupidly obvious that I'm overlooking here? Shouldn't I be able to run this on different ports? If not, why not? If I have to use 80:80, but System is already using that port, won't I have some further problems if I try to kill that pid?

PS C:\Users\david.zemens\Source\Repos\linux_tweet_app> netstat -a -n -o | findstr :80 | findstr LISTENING
  TCP    0.0.0.0:80             0.0.0.0:0              LISTENING       4
  TCP    0.0.0.0:8003           0.0.0.0:0              LISTENING       4
  TCP    0.0.0.0:8080           0.0.0.0:0              LISTENING       1348
  TCP    0.0.0.0:8081           0.0.0.0:0              LISTENING       4688
  TCP    127.0.0.1:8080         0.0.0.0:0              LISTENING       2016
  TCP    127.0.0.1:8082         0.0.0.0:0              LISTENING       28536
  TCP    [::]:80                [::]:0                 LISTENING       4
  TCP    [::]:8003              [::]:0                 LISTENING       4
  TCP    [::]:8080              [::]:0                 LISTENING       1348
  TCP    [::]:8081              [::]:0                 LISTENING       4688

I made a small change in the Dockerfile changing EXPOSE 80 443 to EXPOSE 1337 443 and I'm now able to view my app by navigating to localhost:1337 in my browser. I think that will get me through the next steps in the training module, but still curious if I'm doing something wrong.

This seems to work regardless of the change in Dockerfile (I've removed and republished after changing Dockerfile).

PS C:\Users\david.zemens\Source\Repos\linux_tweet_app> docker container run --detach --publish 1337:80 --name linux_tweet_app $DOCKERID/linux_tweet_app:1.0

enter image description here

like image 862
David Zemens Avatar asked Sep 11 '19 14:09

David Zemens


People also ask

Does Docker use port 8080?

Docker also finds ports you expose with --expose 8080 (assuming you want to expose port 8080). Docker maps all of these ports to a host port within a given epehmeral port range . You can find the configuration for these ports (usually 32768 to 61000) in /proc/sys/net/ipv4/ip_local_port_range .

Why is Docker not working Windows 10?

Operating System. If you do not run a 64-bit version of Windows Windows 10 Pro, Enterprise, or Education; 1511 November update, Build 10586 or later, you cannot run Docker for Windows. You can install Docker Toolbox if you have a 64-bit version of Windows 7 or later. Alternately, you do have the option to upgrade.

What port should I use for Docker?

Map TCP port 80 in the container to TCP port 8080 on the Docker host, and map UDP port 80 in the container to UDP port 8080 on the Docker host.


3 Answers

Try this

> net stop winnat
> docker start ...
> net start winnat
like image 187
KR93 Avatar answered Oct 09 '22 09:10

KR93


A part of the problem is that you're using the wrong mapping. The application uses the port 80, but you're mapping the ports 1337 to 1337.

The correct command should be:

PS C:\Users\david.zemens\Source\Repos\linux_tweet_app> docker container run --detach --publish 1337:80 --name linux_tweet_app $DOCKERID/linux_tweet_app:1.0
like image 42
Stefano Avatar answered Oct 09 '22 11:10

Stefano


It may be because your IIS or some other server is already running on port 80. Try stop the IIS and it should work.

Reference: https://forums.docker.com/t/error-starting-userland-proxy-listen-tcp-0-0-0-0-bind-an-attempt-was-made-to-access-a-socket-in-a-way-forbidden-by-its-access-permissions/81299/7

like image 37
himanshupareek66 Avatar answered Oct 09 '22 11:10

himanshupareek66