Docker networks support the ip-range setting so the network doesn't overlap already existing external networks:
$ docker network create --help
Usage: docker network create [OPTIONS] NETWORK-NAME
Creates a new network with a name specified by the user
--aux-address=map[] auxiliary ipv4 or ipv6 addresses used by Network driver
-d, --driver=bridge Driver to manage the Network
--gateway=[] ipv4 or ipv6 Gateway for the master subnet
--help Print usage
--internal restricts external access to the network
--ip-range=[] allocate container ip from a sub-range
--ipam-driver=default IP Address Management Driver
--ipam-opt=map[] set IPAM driver specific options
-o, --opt=map[] set driver specific options
--subnet=[] subnet in CIDR format that represents a network segment
But docker compose doesn't:
version '2'
networks:
default:
driver: overlay
ip-range: 192.168.240.0/21
<sic>
$ docker-compose create
ERROR: The Compose file './docker-compose.yml' is invalid because:
networks.default value Additional properties are not allowed ('ip-range' was unexpected)
As per documentation your config is a bit worg, try something like:
networks:
default:
ipam:
driver: overlay
config:
- ip-range: 192.168.240.0/21
I can confirm this issue. The ip-range
option is considered invalid, as well as ip_range
and gateway
:
ERROR: The Compose file './docker-compose.yml' is invalid because:
networks.test.ipam.config value Additional properties are not allowed ('gateway' was unexpected)
docker-compose version: 1.10.0, build 4bd6f1a
docker version: 1.13.0, build 49bf474
my config:
version: "3"
services:
...
networks:
test:
ipam:
driver: default
config:
- gateway: 172.18.0.10
# This line only is working fine:
- subnet: 172.20.0.0/24
# This throws the same error:
- subnet: 172.20.0.0/24
gateway: 172.20.0.10
upgraded to release 1.11.1, still same issue
same problem. it seems as though either the documentation is wrong, or there is a problem with the implementation.
Version 1.13.1-beta42 (15350)
Channel: beta
2ffb2b4915
version: '3'
...
networks:
test:
driver: bridge
ipam:
config:
- subnet: 172.28.0.0/16
ip_range: 172.28.0.0/24
gateway: 172.28.0.255
aux_addreses:
db: 172.28.0.1
ui: 172.28.0.5
$docker-compose up
The Compose file './docker-compose.yml' is invalid because:
networks.test.ipam.config value Additional properties are not allowed ('aux_addreses', 'ip_range', 'gateway' were unexpected)
version: '3'
networks.test.ipam.config value Additional properties are not allowed ('aux_addreses', 'ip_range', 'gateway' were unexpected)
Yep, version 3 doesn't support those options. Use version: '2'
for maximum feature set.
Doesn't yet or won't? If I let the default as is, I get a subnet _and_ a gateway. If I set it myself, the gateway isn't set.
We hope to have feature parity between v2 and v3 in the future, but we aren't at that point yet. Until then, please use version 2 if you need fine-grain control over your network's configuration.
I am using below configuration to assign local IP to the service but getting error in version 3. Do I need to switch back to version 2 to assign distinct IP to each swarm service?
networks:
app_net:
ipam:
driver: default
config:
- ip-range: 172.16.238.0/24
Given that this feature is already supported in v2, isn't adding v3 support as simple as adding these properties to the 3.7 schema? Is there a philosophical reason for not doing this; i.e. is there a plan to handle them in a different way than they worked in v2?
In docker compose v2 it works for me using this syntax:
version: "2"
networks:
default:
ipam:
driver: default
config:
- subnet: 192.168.240.0/21