[root@centos02 ~]# ping www.baidu.com <!–再新开一台服务器,连接公网,安装docker–>
PING www.a.shifen.com (39.156.66.18) 56(84) bytes of data.
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=1 ttl=51 time=19.5 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=2 ttl=51 time=17.3 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=3 ttl=51 time=18.1 ms
[root@centos02 ~]# cd /etc/yum.repos.d/
[root@centos02 yum.repos.d]# ls
local.repo
[root@centos02 yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
<!–下载centos7源–>
[root@centos02 ~]# yum install docker -y <!–安装docker–>
[root@centos02 ~]# systemctl start docker <!–启动docker–>
[root@centos02 ~]# systemctl enable docker <!–设置开机自动启动–>
[root@centos02 ~]# docker pull hub.c.163.com/public/centos:6.7-tools <!–下载镜像–>
[root@centos02 ~]# docker images <!–查看镜像–>
REPOSITORY TAG IMAGE ID CREATED SIZE
hub.c.163.com/public/centos 6.7-tools b2ab0ed558bb 3 years ago 602 MB
[root@centos02 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens32
<!–修改docker宿主机网卡配置信息桥接到br0网卡 –>
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
NAME=ens32
DEVICE=ens32
ONBOOT=yes
BRIDGE=br0 <!–添加此行–>
[root@centos02 ~]# cp /etc/sysconfig/network-scripts/ifcfg-ens32 /etc/sysconfig/network-scripts/ifcfg-br0 <!–创建并生成br0网桥–>
[root@centos02 ~]# vim /etc/sysconfig/network-scripts/ifcfg-br0 <!–编辑br0网卡配置文件–>
TYPE=Bridge <!–修改为Bridge–>
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
NAME=br0 <!–修改名字–>
DEVICE=br0 <!–修改为br0–>
ONBOOT=yes
IPADDR=192.168.100.20 <!–添加宿主机IP地址–>
NETMASK=255.255.255.0
[root@centos02 ~]# systemctl restart network <!–重新启动docker宿主机网卡服务–>
[root@centos02 ~]# ifconfig <!–查看docker宿主机网卡信息–>
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.20 netmask 255.255.255.0 broadcast 192.168.100.255
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:0c:29:97:5c:9f txqueuelen 1000 (Ethernet)
ens34: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.104 netmask 255.255.255.0 broadcast 192.168.0.255
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
[root@centos02 ~]# yum -y install git <!–安装git–>
[root@centos02 ~]# git clone https://github.com/jpetazzo/pipework
<!–下载docker容器网络管理工具pipework–>
[root@centos02 ~]# cp pipework/pipework /usr/local/bin/ <!–优化管理命令–>
[root@centos02 ~]# chmod +x /usr/local/bin/pipework <!–添加执行权限–>
[root@centos02 ~]# docker run -d –name centos6.7 –network=none hub.c.163.com/public/centos:6.7-tools <!–通过进行运行容器–>
abec0a6bd3822a2fd702dc44d1cf3043648aadd1a661e577c23701e30ee9df7a
[root@centos02 ~]# pipework br0 centos6.7 192.168.100.102/24
<!–给centos6.7容器配置IP地址–>
[root@centos02 ~]# docker exec -it centos6.7 /bin/bash <!–登录centos6.7容器–>
[root@abec0a6bd382 /]# ifconfig <!–查看IP地址–>
eth1 Link encap:Ethernet HWaddr EE:01:B7:99:90:1C
inet addr:192.168.100.102 Bcast:192.168.100.255 Mask:255.255.255.0
[root@abec0a6bd382 /]# ping 192.168.100.101 <!—->
PING 192.168.100.101 (192.168.100.101) 56(84) bytes of data.
64 bytes from 192.168.100.101: icmp_seq=1 ttl=64 time=0.660 ms
64 bytes from 192.168.100.101: icmp_seq=2 ttl=64 time=0.865 ms
64 bytes from 192.168.100.101: icmp_seq=3 ttl=64 time=0.382 ms
[root@abec0a6bd382 /]# ping 192.168.100.10 <!—->
PING 192.168.100.10 (192.168.100.10) 56(84) bytes of data.
64 bytes from 192.168.100.10: icmp_seq=1 ttl=64 time=0.632 ms
64 bytes from 192.168.100.10: icmp_seq=2 ttl=64 time=0.732 ms
64 bytes from 192.168.100.10: icmp_seq=3 ttl=64 time=0.796 ms
[root@abec0a6bd382 /]# ping 192.168.100.20 <!—->
PING 192.168.100.20 (192.168.100.20) 56(84) bytes of data.
64 bytes from 192.168.100.20: icmp_seq=1 ttl=64 time=0.144 ms
64 bytes from 192.168.100.20: icmp_seq=2 ttl=64 time=0.094 ms
64 bytes from 192.168.100.20: icmp_seq=3 ttl=64 time=0.043 ms