| 知乎专栏 | 多维度架构 |
查看 docker0 的IP地址
root@production:~# ifconfig docker0
docker0 Link encap:Ethernet HWaddr 02:42:ad:68:6b:cf
inet addr:172.18.0.1 Bcast:172.18.255.255 Mask:255.255.0.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
修改 docker0 的IP地址
root@production:~# vim /etc/docker/daemon.json
root@production:~# cat /etc/docker/daemon.json
{
"bip":"172.100.10.1/24"
}
root@production:~# systemctl restart docker
root@production:~# ifconfig docker0
docker0 Link encap:Ethernet HWaddr 02:42:ad:68:6b:cf
inet addr:172.100.10.1 Bcast:172.100.10.255 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
![]() | 提示 |
|---|---|
|
曾经遇到一个案例,阿里云使用172.18.0.0/16作为RDS内网IP地址,ECS安装了docker后无法链接RDS属于,因为docker修改了路由表,将docker换到其他网段后工作正常。 |
docker run -d --privileged -p 9000:9000 --ip 192.168.5.2 \ --restart=always \ -v /var/run/docker.sock:/var/run/docker.sock \ -v /opt/portainer:/data \ portainer/portainer
docker network create \ --driver=overlay \ --subnet=172.12.0.0/16 \ --ip-range=172.12.0.0/16 \ --gateway=172.12.0.1 \ --attachable \ test
iMac:redis neo$ docker network ls NETWORK ID NAME DRIVER SCOPE 786efe30f42d bridge bridge local 51e2b21d7daa docker_gwbridge bridge local 96ba0de26cd2 host host local 7r7k9robn0uu ingress overlay swarm cbf078a5f121 none null local d851mrlkludv redis_default overlay swarm q0h9awx86ef4 registry_default overlay swarm cf585ea9ceb4 registry_default bridge local gvcz5y66ovrl test overlay swarm
查看详细信息
iMac:redis neo$ docker network inspect test
[
{
"Name": "test",
"Id": "gvcz5y66ovrlqfaxb02zx026t",
"Created": "2020-09-26T14:07:49.037581155Z",
"Scope": "swarm",
"Driver": "overlay",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.12.0.0/16",
"IPRange": "172.12.0.0/16",
"Gateway": "172.12.0.1"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": null,
"Options": {
"com.docker.network.driver.overlay.vxlanid_list": "4104"
},
"Labels": null
}
]
[root@localhost ~]# docker inspect --format="{{ .State.Pid }}" b279738af403
2180
[root@localhost ~]# mkdir -p /var/run/netns
[root@localhost ~]# ln -s /proc/2180/ns/net /var/run/netns/2180
[root@localhost ~]# ip netns exec 2180 ip route
default via 192.168.49.1 dev eth0
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
192.168.30.0/24 via 192.168.49.1 dev eth0
192.168.49.0/24 dev eth0 proto kernel scope link src 192.168.49.2