docker 访问宿主机

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013705066/article/details/81978460

有时候就需要在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.

猜你喜欢

转载自blog.csdn.net/u013705066/article/details/81978460