我试图使用docker-compose创建一个容器,使其同时连接两个网络。我希望其中一个网络是宿主机网络(就像运行“docker run --net=host”一样),另一个是用户定义的网络。
我尝试了以下方法:
我将翻译以下内容:
我尝试了以下方法:
version: '3'
networks:
test:
driver: bridge
host:
external: true
services:
helloworld:
image: python:3.6-alpine
networks:
- test
- host
cap_add:
- NET_ADMIN
- NET_RAW
ports:
- 0.0.0.0:8080:8080
command: sh -c "cd /tmp && python -m http.server 8080"
我将翻译以下内容:
我遇到了这个错误:
$ docker-compose up
Removing blah_helloworld_1
Starting 8743618e8af4_blah_helloworld_1 ... error
ERROR: for 8743618e8af4_blah_helloworld_1 network-scoped alias is supported only for containers in user defined networks
ERROR: for helloworld network-scoped alias is supported only for containers in user defined networks
ERROR: Encountered errors while bringing up the project.
network_mode
属性。但是,这与networks
属性是互斥的。如果你使用network_mode: "host"
,你的服务将可以访问test
网络,而无需显式加入。你想要实现什么目标? - vstm