Docker connection issues - refused to connect

2019-08-27 18:26发布

I'm using Mac OSX and I'm on part 4 of the Docker tutorial, but I cannot access the site through my web browser. When I visit either IP address given from the docker-machine ls command I get a "this site can't be reached" error. If I specify port 2377, such as http://192.168.99.100:2377/ (also used port 2376) I can at least connect but it results in a "192.168.99.100 sent an invalid response" error message.

When I try a curl request to both port 80 and 8080 it fails

curl http://192.168.99.100:80
curl: (7) Failed to connect to 192.168.99.100 port 80: Connection refused

If I specify port 2376 or 2377 it will connect, but I don't get any content back, which seems to coincide with the "invalid response" error I get when visiting directly from my web browser

curl --verbose 192.168.99.100:2376
* Rebuilt URL to: 192.168.99.100:2376/
*   Trying 192.168.99.100...
* TCP_NODELAY set
* Connected to 192.168.99.100 (192.168.99.100) port 2376 (#0)
> GET / HTTP/1.1
> Host: 192.168.99.100:2376
> User-Agent: curl/7.54.0
> Accept: */*
> 

* Connection #0 to host 192.168.99.100 left intact

Here's the output when I run docker-machine ls

NAME    ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER        ERRORS
myvm1   *        virtualbox   Running   tcp://192.168.99.100:2376           v18.06.1-ce   
myvm2   -        virtualbox   Running   tcp://192.168.99.101:2376           v18.06.1-ce   

I think I have a port mapping issue with the VM's, but I'm not sure what to do. I tried the accepted answer in this question, but still no luck.

Update

I tried port forwarding as suggested in this post, but had no luck with that either. I added the following and verified in the VirtualBox manager that the forwarding rules are present

VBoxManage controlvm "myvm1" natpf1 "tcp-port8000,tcp,,80,,80";
VBoxManage controlvm "myvm2" natpf1 "tcp-port8000,tcp,,80,,80";

I've also added forwarding for port 7946 TCP/UDP and Port 4789 UDP to each of the two vm's

1条回答
Anthone
2楼-- · 2019-08-27 19:01

I came across the same problem today when study part4. After a long time searching for solutions but didn't work, then I checked my docker-compose.yml file to see the ports mapping and found the right port. For me is curl -v http://192.168.99.100:4000, and it worked:

enter image description here

查看更多
登录 后发表回答