Con*_*ham 7 docker docker-compose docker-network
我有 2 个图像,我想通过 compose 的默认桥接网络相互通信,但我也希望它们能够访问我的主机网络。
为了允许图像在 compose 的默认桥接网络中相互通信,我不需要执行任何操作:
version: '3.4'
services:
hello:
image: hello-world
world:
image: hello-world
Run Code Online (Sandbox Code Playgroud)
通过上述规范,服务可以通过使用 DNS 名称来hello
引用服务world
world
如果我希望 hello 服务能够与我的主机网络交互,我可以添加network_mode: host
到规范中。
version: '3.4'
services:
hello:
image: hello-world
network_mode: host
world:
image: hello-world
Run Code Online (Sandbox Code Playgroud)
这允许hello
服务访问我的主机网络,但无法再world
通过 compose 的内置 DNS 进行访问。我怎样才能同时实现这两个目标?
我尝试创建自定义网络,但自定义网络无法使用主机驱动程序,并且我无法network_mode
与以下命令结合使用networks
:
这不起作用:
version: '3.4'
services:
hello:
image: hello-world
network_mode: host
networks:
- bridge
world:
image: hello-world
networks:
- bridge
networks:
test:
driver: bridge
Run Code Online (Sandbox Code Playgroud)
$ docker-compose up
ERROR: 'network_mode' and 'networks' cannot be combined
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4161 次 |
最近记录: |