在centos7上安装docker
- 查看docker的版本
[root@docker2 ~]# yum list| grep docker
docker.x86_64 2:1.12.6-68.gitec8512b.el7.centos
docker-client.x86_64 2:1.12.6-68.gitec8512b.el7.centos
docker-common.x86_64 2:1.12.6-68.gitec8512b.el7.centos
......
docker版本为1.12.6
- 安装docker
yum install -y docker
- 网络配置
见CentOS7.2网络配置
CentOS7下Docker桥接网络配置
物理机的IP信息
网卡eth0的ip:
192.168.175.211
要桥接的网卡br0的ip:192.168.175.88
网关:192.168.175.2
配置桥接网络
-
停止docker服务
service docker stop
-
删除docker0网卡
ip link set dev docker0 down
brctl delbr docker0
如果没有bctl命令,需要安装yum install -y bridge-utils
-
新建桥接网卡br0
brctl addbr br0
ip link set dev br0 up
ip addr add 192.168.175.88/24 dev br0
-
为br0分配物理网络中的ip地址
ip addr del 192.168.175.211/24 dev eth0
#将宿主机网卡的IP删除(到这一步会断网)
brctl addif br0 eth0
#将宿主机网卡挂到br0上
ip route del default
#删除原路由
route -n
ip route add default via 192.168.175.2 dev br0
#为br0设置路由 -
到这里可以用
192.168.175.88
连接主机
配置docker
-
配置桥接网络
vim /etc/sysconfig/docker-network
,其他系统可能在/etc/sysconfig/docker
下哦。
在DOCKER_NETWORK_OPTIONS
添加-b=br0
,如下:
DOCKER_NETWORK_OPTIONS="-b=br0"
-
配置加速器
vi /etc/docker/daemon.json
{
"registry-mirrors": ["你的加速器地址"]
}
-
启动docker
service docker start
-
安装pipework
git clone https://github.com/jpetazzo/pipework
如果没有git,请先安装git:yum -y install git
- 将pipework拷贝到系统运行目录下
cp ~/pipework/pipework /usr/local/bin/
-
启动容器并设置网络
docker run -itd --net=none --name=cs7.01 centos:latest /bin/bash
#创建并启动容器,给容器命名为cs7.01
pipework br0 cs7.01 192.168.175.89/24@192.168.175.88
-
进入容器查看ip
docker attach cs7.01
[root@f008dfae260f /]# ifconfig
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.175.89 netmask 255.255.255.0 broadcast 192.168.175.255
inet6 fe80::d489:3ff:fee2:20a prefixlen 64 scopeid 0x20<link>
ether d6:89:03:e2:02:0a txqueuelen 1000 (Ethernet)
RX packets 4121 bytes 12249844 (11.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3516 bytes 194671 (190.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@f008dfae260f /]#
网友评论