Compose: How does compose chooses subnet for default network?

Created on 16 Jan 2017  路  22Comments  路  Source: docker/compose

I have my docker engine startup configured with:

{
  "bip": "172.80.0.1/16",
  "fixed-cidr": "172.80.0.0/16"
}

but if I start a compose without any network config it creates a bridge with subnet 172.17.0.0/16.

When the docker engine was running with default config it created docker0 with subnet 172.17.0.0/16 and when running compose the bridge network was created with subnet 172.18.0.0/16

Is this the expected behavior? How / where does compose gets the "default" network config from? Is there a way to change this globally to avoid spreading the following config on every compose.yaml?

networks:
  default:
    ipam:
      config:
        - subnet: 172.177.0.0/16

Thanks.

arenetworking kinquestion

Most helpful comment

I'm also running into this issue.

Another way around this is to set the default-address-pools in your docker daemon.json, which will put containers using both docker and docker-compose into your desired subnet.

[~]$ cat ~/.docker/daemon.json
{
  "debug" : true,
  "default-address-pools" : [
    {
      "base" : "172.31.0.0/16",
      "size" : 24
    }
  ]
}

All 22 comments

Unless specified, Compose will leave those details to the Engine at creation time.

I'm also seeing the same behaviour as described by OP.

Docker version 1.12.6, build 7392c3b/1.12.6

When running docker-compose up, it creates 2 bridge interfaces (other than docker0) with ip ranges 172.17.0.0/16 and 172.18.0.0/16, despite passing --bip=192.168.1.5/24 --fixed-cidr=192.168.1.5/24 to the main docker engine.

Is there any way to override the default bridge networks without modifying docker-composer.yml?

@adenot Like I said, this is not something docker-compose configures unless specified in the Compose file. If you witness some unexpected behavior, please create an issue on the Engine bug tracker: https://github.com/docker/docker/issues

I have observed the same behavior as OP. Docker engine is started with --bip argument, but it is ignored by docker-compose, which set up an additional bridge interface in addition to the docker0 interface. It is named br-f4a912f7750b and has the typical Docker 172.17.x.x format, which happens to conflict with the network I'm currently using. Confirmed with Docker version 1.12.6, build 78d1802 and docker-compose version 1.12.0, build b31ff33.

As stated by @shin this is handled by the docker engine. Currently there is no way to specify the default pool, there is a PR open here https://github.com/docker/docker/pull/29376

Same issue on Fedora 26 (Works on centos 7 however...) any ideas?
Docker version 1.13.1
docker compose version 1.16.1

Current status:
The PR with a possible fix is being held up because of issues with docker swarm. I suggest going to that PR and weighing in on the discussion.

simple workaround:
configure routing in your operating system for existing networks and docker will not use these networks.
e.g.

route add -net 172.17.0.0 netmask 255.255.0.0 gw 172.16.0.1
route add -net 172.18.0.0 netmask 255.255.0.0 gw 172.16.0.1

see your os manual for persisting these settings

same issue on opensuse tumbleweed :(, why this is closed ?

Nice workaround @vogsphar ! Works like a charm

well actually you can first create that supposed network and then run docker-compose up -d

     docker-compose down
    docker network create --subnet=[your range] [the network name that would create if you run compose up -d]
    docker-compose up -d

Hi for resolve this in your docker-compose need add a ip configuration

version : '3'

services:
  nginx:
    image: nginx
    networks:
          default:
            aliases:
              - aerogear.sistemasfamsaqa.com
networks:
  default:
    driver: bridge
    ipam:
      driver: default
      config:
      - subnet:  10.103.0.1/16

@ripper2hl:

This it's tedious if you have many projects with compose. I use it because there is not solution for now.

Yes i know :(

I'm also running into this issue.

Another way around this is to set the default-address-pools in your docker daemon.json, which will put containers using both docker and docker-compose into your desired subnet.

[~]$ cat ~/.docker/daemon.json
{
  "debug" : true,
  "default-address-pools" : [
    {
      "base" : "172.31.0.0/16",
      "size" : 24
    }
  ]
}

default-address-pools is only available in docker (18.09.1) for linux, not for windows or mac.

nice !

I'm also running into this issue.

Another way around this is to set the default-address-pools in your docker daemon.json, which will put containers using both docker and docker-compose into your desired subnet.

[~]$ cat ~/.docker/daemon.json
{
  "debug" : true,
  "default-address-pools" : [
    {
      "base" : "172.31.0.0/16",
      "size" : 24
    }
  ]
}

nice ! Thank you

Docker for Mac Version 2.0.0.3 (31259) supports default-address-pools, but the setting doesn't affect containers inside docker-compose.

The workaround with networks doesn't work too.

@ilyaglow did you find a solution to this on Mac?

any further development with this?
looking for solution for Mac and Windows if possible

Hi, my docker is currently on Version 1.13.1 on Centos. Default-Address-Pools seem to be missing. It won't start with that option enabled in the daemon.json.

This is the error I get
dockerd-current[11625]: unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives don't match any configuration option: default-address-pools

Was this page helpful?
0 / 5 - 0 ratings