容器,是一种轻量级的虚拟化技术,和虚拟机一样都是为了创造隔离环境。但是它不像VM采用操作系统级的资源隔离,容器采用的是进程级的系统隔离。
容器在没有配置网络之前是个信息孤岛不能与外部连通,为了容器能与外部通讯需要给容器配置网络。
容器网络架构图:
安装步骤如下:
1.安装虚拟网桥
yum install -y bridge-utils
查看:
brctl show
可以看到在安装docker之后就有一个docker0网桥
2.创建网桥
brctl addbr foonet0
ip link set foonet0 up
ip addr add 10.12.0.1/24 dev foonet0
3.创建veth设备
ip link add name veth0-host type veth peer name veth0-ns
ip link set veth0-host up
brctl addif foonet0 veth0-host
4.创建一个net namespace
ip netns add mycontainer
ip link set veth0-ns netns mycontainer
5.设置ns里面的网卡名称和启动
ip netns add mycontainer
ip link set veth0-ns netns mycontainer