Mac的docker并没有docker0这个桥接的网卡,所以无法通过容器的网关IP访问宿主机的服务,这个好坑。。。 查询了官方文档给的解释如下:
There is no docker0 bridge on macOS Because of the way networking is implemented in Docker Desktop for Mac, you cannot see a docker0 interface on the host. This interface is actually within the virtual machine.
容器与宿主机的网络连接是通过Docker Desktop实现的,要访问只能通过域名host.docker.internal
访问,官方说明如下:
I WANT TO CONNECT FROM A CONTAINER TO A SERVICE ON THE HOST
The host has a changing IP address (or none if you have no network access). From 18.03 onwards our recommendation is to connect to the special DNS name
host.docker.internal
, which resolves to the internal IP address used by the host. This is for development purpose and will not work in a production environment outside of Docker Desktop for Mac.