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
.
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.
Use the docker network rm command to remove a user-defined bridge network. If containers are currently connected to the network, disconnect them first.
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 thedocker0
bridge, using standard CIDR notation. For example:192.168.1.5/24
.
--fixed-cidr=CIDR
: restrict the IP range from thedocker0
subnet, using standard CIDR notation. For example:172.16.1.0/28
. This range must be an IPv4 range for fixed IPs, such as10.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 the192.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"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With