docker-compose文件中设置网络
程序员文章站
2022-05-15 13:10:24
...
docker-compose.file
version: '3'
services:
my-gotest:
container_name: testProject
image: hub.docker.com/benben/my-gotest:test
restart: always
ports:
- 8080:8080
networks:
- bennet
networks:
bennet:
external: true
如果在docker-compose
文件中设置external
为true
,那么使用docker-compose up -d
来启动服务时,首先docker
引擎会查找external
声明的网络,找到后进行连接。否则会提示错误:
ERROR: Network bennet declared as external, but could not be found. Please create the network manually using `docker network create bennet` and try again.
当其值为false
时,会自动创建一个testProject_bennet
的网络,如果没有networks
字段时,会创建一个testProject_default
的网络。