我想指定docker容器的IP地址范围到主机,这也是在this tutor之后实现的,尽管全局网络仍然无法访问它。当然,我已经检查了通过ifconfig
指定的IP。
root@ubuntu:~# brctl show
bridge name bridge id STP enabled interfaces
docker0 8000.000000000000 no
root@ubuntu:~# brctl addbr bridge0
root@ubuntu:~# ip addr add 10.0.3.1/24 dev bridge0
root@ubuntu:~# ip link set dev bridge0 up
root@ubuntu:~# ip addr show bridge0
4: bridge0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN
link/ether 0e:3a:46:ac:fe:57 brd ff:ff:ff:ff:ff:ff
inet 10.0.3.1/24 scope global bridge0
inet6 fe80::c3a:46ff:feac:fe57/64 scope link
valid_lft forever preferred_lft forever
root@ubuntu:~# echo 'DOCKER_OPTS="-b=bridge0"' >> /etc/default/docker
root@ubuntu:~# service docker restart
docker stop/waiting
docker start/running, process 3166
然后,我运行ubuntu:14.04容器
root@ubuntu:~# docker run -t -i ubuntu:14.04 /bin/bash
root@630046b814dc:/# ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:0a:00:03:02
inet addr:10.0.3.2 Bcast:0.0.0.0 Mask:255.255.255.0
inet6 addr: fe80::42:aff:fe00:302/64 Scope:Link
UP BROADCAST RUNNING MTU:1500 Metric:1
RX packets:3 errors:0 dropped:0 overruns:0 frame:0
TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:238 (238.0 B) TX bytes:328 (328.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 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)
当我尝试ping主机IP
时root@630046b814dc:/# ping 10.0.3.87
PING 10.0.3.87 (10.0.3.87) 56(84) bytes of data.
From 10.0.3.2 icmp_seq=1 Destination Host Unreachable
From 10.0.3.2 icmp_seq=2 Destination Host Unreachable
From 10.0.3.2 icmp_seq=3 Destination Host Unreachable