-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docker Nginx 容器直接访问宿主机 #8
Comments
https://docs.docker.com/network/host/ 官网的host network介绍中有这么一句“The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.”,所以windows下面不能用,, |
@mystterio 是的,感谢补充~ |
mark |
这个--network host只支持linux |
@suncunhu 18.03版本后,可以使用 |
在使用 nginx docker 容器配置反向代理的时候,默认不能直接使用 localhost,因为访问它指向的是这个容器本身。而本机的内网 ip 时常改变,如果没有联网还会没有内网地址,开发测试非常的不方便。
在 Desktop 环境下,可以使用
host.docker.internal
docker 提供的特殊 DNS 访问宿主机。如果是 Linux 环境还可以使用 docker 提供的
host networking
,将容器的端口直接发布到宿主机上。举个例子:如果 Dockerfile EXPOSE的端口是 80,那么使用
host networking
方式 启动容器,就可以直接用宿主机的ip通过80端口访问这个服务,不需要指定--port
。同时容器也可以直接访问宿主机其他端口的服务,不需要通过内网ip。方法很简单,命令启动时,加上
--network host
就可以了:在 docker-compose.yml 中使用:
ref:
The text was updated successfully, but these errors were encountered: