在 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 手动创建网络服务层
,然后重试.
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 制作网络.它们将被命名为
使用 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(当主机低于 1500 mtu 并且路径 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
当您希望两个组合设置中的服务相互通信或者您有一个手动创建的网络时,更有意义.
external
makes more sense when you want services in two compose setups to talk to each other or you have a manually created network.
这篇关于在 Docker Compose 中自动创建网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!