我localhost:8000在主机上有一个打开的。具体来说:
$ php -S localhost:8000
PHP 7.1.19 Development Server started at Tue Jul 16 09:49:08 2019
Listening on http://localhost:8000
Run Code Online (Sandbox Code Playgroud)
我可以在主机上执行curl -i http://localhost:8000以获得响应,我也可以通过主机浏览器访问它,完全没有问题。
但是,当我尝试访问 Mac 上 docker 容器上的主机时,连接被拒绝:
$ curl -i http://host.docker.internal:8000
curl: (7) Failed to connect to host.docker.internal port 8000: Connection refused
$ telnet host.docker.internal 8000
Trying 192.168.65.2...
telnet: Unable to connect to remote host: Connection refused
Run Code Online (Sandbox Code Playgroud)
host.docker.internal从命令中可以看出,docker 容器可以解析 DNS telnet,我也可以ping,但连接被拒绝。
$ ping host.docker.internal
PING host.docker.internal (192.168.65.2) 56(84) bytes of data.
64 …Run Code Online (Sandbox Code Playgroud)