harbor修改了docker默认网卡失效原因

问题

修改了docker的默认网段,但是harbor启动时候又会出现docker默认的网段,故现找下原因

Docker修改默认的网段

删除原有配置

1
2
3
4
service docker stop
ip link set dev docker0 down
brctl delbr docker0
iptables -t nat -F POSTROUTING

创建新的网桥

1
2
3
brctl addbr docker0
ip addr add 192.17.10.1/24 dev docker0
ip link set dev docker0 up

配置Docker的文件

注意: 这里是 增加下面的配置

1
2
3
4
5
6
vi /etc/docker/daemon.json
[root@bogon ~]# cat /etc/docker/daemon.json ##追加的即可
{"registry-mirrors": ["http://224ac393.m.daocloud.io"],
"bip": "192.17.10.1/24"
}
[root@bogon ~]# systemctl restart docker

启动harbor

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[root@ceph harbor]# docker-compose up -d
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating registry ... done
Creating harbor-db ... done
Creating harbor-adminserver ... done
Creating harbor-ui ... done
Creating nginx ... done
Creating harbor-jobservice ... done
[root@ceph harbor]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:50:56:b1:6e:40 brd ff:ff:ff:ff:ff:ff
inet 192.168.6.101/24 brd 192.168.6.255 scope global noprefixroute ens160
valid_lft forever preferred_lft forever
inet6 fe80::250:56ff:feb1:6e40/64 scope link
valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:47:80:80:47 brd ff:ff:ff:ff:ff:ff
inet 192.17.10.1/24 brd 172.17.10.255 scope global docker0
valid_lft forever preferred_lft forever
4: br-0b90f672a48b: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:c0:31:37:91 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.18.255.255 scope global br-0b90f672a48b
valid_lft forever preferred_lft forever
inet6 fe80::42:c0ff:fe31:3791/64 scope link

可以看到又启动了docker的默认网段,由于docker-compose up创建新的网桥的时候都是使用默认的172网段的

解决

1
2
3
4
5
6
7
8
9
10
[root@ceph harbor]# cat /etc/docker/daemon.json
{
"debug" : true,
"default-address-pools" : [
{
"base" : "12.11.0.0/16",
"size" : 24
}
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[root@ceph harbor]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:50:56:b1:6e:40 brd ff:ff:ff:ff:ff:ff
inet 192.168.6.101/24 brd 192.168.6.255 scope global noprefixroute ens160
valid_lft forever preferred_lft forever
inet6 fe80::250:56ff:feb1:6e40/64 scope link
valid_lft forever preferred_lft forever
19: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:b5:b4:c9:0b brd ff:ff:ff:ff:ff:ff
inet 12.11.0.1/24 brd 12.11.0.255 scope global docker0
valid_lft forever preferred_lft forever
20: br-6a72f517b541: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:e4:23:a8:f5 brd ff:ff:ff:ff:ff:ff
inet 12.11.1.1/24 brd 12.11.1.255 scope global br-6a72f517b541
valid_lft forever preferred_lft forever
inet6 fe80::42:e4ff:fe23:a8f5/64 scope link
valid_lft forever preferred_lft forever

也可以直接修改docker-compose文件

1
2
3
4
5
6
networks:
harbor:
external: false
ipam:
config:
- subnet: 10.48.255.120/24
Donate