![](/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.