##1. 服务器信息
网络: 192.168.1.1/24 网关: 192.168.1.1
docker1 centos7 192.168.1.200
docker2 centos7 192.168.1.201
##2.docker的安装
关闭selinux
# setenforce 0
# vi /etc/selinux/config
修改为SELINUX=disabled
使用yum安装docker
# yum install docker-io -y
启动docker
# service docker start
检查docker
# docker info
......
下载镜像
# docker pull centos
##3.创建网桥
# vi /etc/sysconfig/network-scripts/ifcfg-br0
TYPE=Bridge
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
DEVICE=br0
ONBOOT=yes
IPADDR=192.168.1.200 #配置为机器的ip
PREFIX=16
GATEWAY=192.168.1.1
DNS1=114.114.114.114 #DNS服务器地址
修改物理网卡配置
# vi /etc/sysconfig/network-scripts/ifcfg-enxxxx
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=d0d3289e-9c2c-45f7-a569-c55aca9f0e8a
DEVICE=ens37
ONBOOT=yes
BRIDGE=br0 #add
重启网络
# service network restart
设置docker启动参数,使用dr0网桥,设置单独的fixed-cidr
# vi /etc/sysconfig/docker
在OPTIONS='--selinux-enabled'这行中修改为OPTIONS='--selinux-enabled -b=br0 --fixed-cidr=10.2.1.0/24' 即让docker服务启动时使用br0网卡进行桥接
重启docker
# service docker restart
##4.安装pipework
# wget https://github.com/jpetazzo/pipework/archive/master.zip
# unzip master.zip
# cp pipework-master/pipework /usr/local/bin/
# chmod +x /usr/local/bin/pipework
启动一个docker
# docker run -itd --net=none --name=test centos /bin/bash
查看docker启动的container
# docker ps
查看network namespace
# docker inspect -f "{{.State.Pid}}" 232621e9e9fb
19778
pipework将192.168.1.202ip绑定到test并将网关指到192,168.1.1
# pipework br0 test 192.168.1.202/24@192.168.1.1
docker2上测试能否ping通docker1
# ping 192.168.1.202
##5.同上安装docker2
进去启动的docker容器内 # docker exec -it b780a /bin/bash
\# ping 192.168.1.202
.....
#注意:
- virtualbox做实验的话注意把网卡的混杂模式设成全部允许然后重启,一开始没设,结果死活都不通,搞了好久。