有时候就需要在docker容器里访问宿主机提供的服务。
例如容器里的应用需要访问宿主机的mysql服务。

方案一:
宿主机执行ifconfig
会看到docker0那个ip,可以使用来访问宿主机

方案二:
docker 18.03 加入了一个 feature,在容器中可以通过 host.docker.internal来访问主机
Use your internal IP address or connect to the special DNS name host.docker.internal which will resolve to the internal IP address used by the host.

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐