Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forbid docker to use specific network

Is there a way to tell docker to not use some specific network when runing docker-compose up?

I am using some out of the box examples (hyperledger) and each time docker takes an address that breaks my remote connection.

[xxx@xxx fabric]$ docker network inspect some_network
[
    {
        "Name": "some_network",
        "Id": "xxx",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.30.0.0/16",
                    "Gateway": "172.30.0.1/16"
                }
            ]
        },
        "Internal": false,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
]

What I would like is to tell docker (without editing the docker-compose.yaml file) to never use the network 172.30.0.0/16.

like image 475
alacambra Avatar asked May 12 '17 06:05

alacambra


People also ask

How do I disable network Docker?

If you want to completely disable the networking stack on a container, you can use the --network none flag when starting the container. Within the container, only the loopback device is created.

How do I remove a network Docker bridge?

Use the docker network rm command to remove a user-defined bridge network. If containers are currently connected to the network, disconnect them first.


1 Answers

When you create a network inside docker-compose.yml, you can specify IP range, subnet, gateway, etc. You can do it this way.

version: "3"

services:    
  service1:
    build: .
    ...

networks:
  default:
    subnet: 172.28.0.0/16
    ip-range: 172.28.5.0/24
    gateway: 172.28.5.254

To do this in the Docker daemon, you have pass --bip and --fixed-cidr parameters.

From Docker docs: https://docs.docker.com/engine/userguide/networking/default_network/custom-docker0/

--bip=CIDR: supply a specific IP address and netmask for the docker0 bridge, using standard CIDR notation. For example: 192.168.1.5/24.

--fixed-cidr=CIDR: restrict the IP range from the docker0 subnet, using standard CIDR notation. For example: 172.16.1.0/28. This range must be an IPv4 range for fixed IPs, such as 10.20.0.0/16, and must be a subset of the bridge IP range (docker0 or set using --bridge). For example, with --fixed-cidr=192.168.1.0/25, IPs for your containers will be chosen from the first half of addresses included in the 192.168.1.0/24 subnet.

To make this changes permanent, create or edit /etc/docker/daemon.json and add options bip and fixed-cidr.

{
"bip": "192.168.1.5/24",
"fixed-cidr": "192.168.1.0/25"
}
like image 125
kstromeiraos Avatar answered Nov 15 '22 04:11

kstromeiraos