![](/img/trans.png)
[英]How to combine host network with the default network in docker-compose
[英]How to expose host network to docker container in docker-compose?
好吧,问题很简单; 执行docker-compose
时如何传递--net=host
?
eclipse:
build:
context: .
dockerfile: eclipse-dockerfile
image: eclipse-docker:latest
volumes:
- "$HOME/.Xauthority:/root/.Xauthority:rw"
networks:
- "host"
environment:
- DISPLAY=$DISPLAY
显然不起作用
您可以使用network_mode: "host"
At the time on this post 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.
这是一个快速演示:
docker-compose.yml
version: '3'
services:
web-svc-in-host-net:
image: nginx
network_mode: "host"
组成:
docker-compose up -d
在 localhost 上访问 nginx(nginx 图像默认在端口 80 上侦听 - 因此无需在 curl 示例中指定端口):
curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
[...]
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.