如果设置了variables,如何configurationdocker组合使用给定的子网,或者如果不是,select自己?
我在我的泊坞窗撰写文件中有以下networkingconfiguration。
networks: default: ipam: driver: default config: - subnet: ${DOCKER_SUBNET}
当设置DOCKER_SUBNET
,按照预期使用该variables中指定的子网。 当variables没有设置,我得到: ERROR: Invalid subnet : invalid CIDR address:
因为variables是空白的(这是完全合理的)。
有没有一种方法来configurationipam驱动程序,如果没有设置DOCKER_SUBNET
variables, DOCKER_SUBNET
-compose将select一个可用的子网,如果没有给出ipamconfiguration,通常会这样做?
如果您没有为networking提供任何ipam
configuration,撰写将只会select一个可用的子网。 撰写没有先进的function来即时修改configuration。
您可以在不使用多个撰写文件或基于模板的系统撰写文件的情况下,使用shell或其他启动docker-compose
命令的语言来做出决定。
从你的服务configuration分离你的networkingconfiguration
docker-compose-net-auto.yml
version: "2.1" networks: default:
docker-compose-net-subnet.yml
version: "2.1" networks: default: ipam: driver: default config: - subnet: ${DOCKER_SUBNET}
然后创build一个脚本launch.sh
,以便select要包含哪个networking文件。
#!/bin/sh if [ -z "$DOCKER_SUBNET" ]; then docker-compose -f docker-compose.yml -f docker-compose-net-auto.yml up else docker-compose -f docker-compose.yml -f docker-compose-net-subnet.yml up fi