Reputation: 3993
I have a number of dev sites I need to dockerise and run locally. I need to give them fixed IP's as they use callbacks from services which need to always hit the same IP.
On my first docker stack it works perfectly
php-fpm:
image: php:fpm
container_name: site1-php-fpm
working_dir: /application
networks:
site1:
ipv4_address: 172.18.0.5
.......
.......
.......
networks:
site1:
driver: bridge
ipam:
config:
- subnet: 172.18.0.0/16
I can access the services via 172.18.0.1/2/3/4/5 as specified in the yaml file. The problem comes when trying to create the next site like so:
php-fpm:
image: php:fpm
container_name: site1-php-fpm
working_dir: /application
networks:
site2:
ipv4_address: 172.18.1.5
.......
.......
.......
networks:
site2:
driver: bridge
ipam:
config:
- subnet: 172.18.1.0/16
My plan was to use 172.18.1.0, 172.18.2.0, 172.18.3.0..... and so on but I get this error:
cannot create network bc0ef736dbefd4622b5ca304e35fe8be3d071fc86ad45b41a161ea300c9ef929 (br-bc0ef736dbef): conflicts with network 2a52c21c5e042d56c47c032d78141c3413766ec6fb248e3a69ee9f794f38b70a (br-2a52c21c5e04): networks have overlapping IPv4
I thought 172.18.0.0 and 172.18.0.1 where different subnets? Or have I got this wrong?
Upvotes: 1
Views: 5753
Reputation: 484
I have a similar error:
Creating network "elk_network1" with driver "bridge" ERROR: cannot create network c64ac781783d8f020494700bedd0f4eed5751e1138f825ef91402134f395dd17 (br-c64ac781783d): conflicts with network 2d48f2e1eb3d16e16e958e52f4a2b48f5424e62ee961bccc4c44d8eff1aa18be (br-2d48f2e1eb3d): networks have overlapping IPv4
I have solved this problem like this following steps:
List all network
$ ip a
If you see the bridge like br-2d48f2e1eb3d
and its status is down, delete it
$ brctl delbr br-2d48f2e1eb3d
Then restart docker
$ service docker restart
Run docker-compose
again. Then docker-compose
will run well.
But in your situation, you first need to change netmask to /24
.
Upvotes: 4
Reputation: 1644
Sub-network mask /16
means that network prefix are the first 16 bits of the address, or in other words the first two numbers - 172.18.
. And in this case they are really overlapping. You have to change sub-network mask to /24
or use different network prefix i.e. 172.18.
, 172.19.
, 172.20.
etc.
Upvotes: 3