在Docker Compose中自动创建网络 [英] Create networks automatically in Docker Compose
问题描述
在Docker等中使用自定义网络时
When using custom networks in Docker like
networks:
default:
external:
name: service-tier
尝试运行该错误,我得到了错误
And try to run that, I´m getting the error
错误:网络服务层已声明为外部,但不能为 成立.请使用
docker network create service-tier
手动创建网络,然后重试.
ERROR: Network service-tier declared as external, but could not be found. Please create the network manually using
docker network create service-tier
and try again.
是否可以通过docker-compose自动创建网络,或者除了首先手动创建网络之外没有其他方法?
Is it possible to create networks automatically with docker-compose or is there no other way than creating them manually first?
推荐答案
external
将使用现有网络.如果您想组成网络,只需执行以下操作:
external
is to use an existing network. If you want compose to make networks you simply do:
networks:
network1:
network2:
..指示组成网络.它们将被命名为<compose-dir>-<network name>
.使用docker network ls
验证创建.
.. to instruct compose to make the networks. They will be named <compose-dir>-<network name>
Verify the creation by using docker network ls
.
您还可以覆盖默认网络或指定更多属性.
You can also override the default network or specify more properties.
networks:
default:
driver: bridge
driver_opts:
com.docker.network.driver.mtu: 1450
..将覆盖默认的网络设置MTU到1450(在主机的MTU低于1500并且路径MTU发现无法正常工作时很方便).有其他网桥驱动程序选项.
.. will override the default network setting MTU to 1450 (handy when the host have lower than 1500 mtu and path mtu discovery doesn't work properly). There are other bridge driver options.
external
更有意义.
这篇关于在Docker Compose中自动创建网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!