docker centos7 配置和宿主机同网段IP
docker centos7 配置和宿主机同网段IP
1、安装brctl 命令
# yum -y install bridge-utils
2、编辑网卡配置文件
# vi ifcfg-eno16777736
TYPE=Ethernet
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=2b04503d-4c0d-4f0f-8790-7b6203739892
DEVICE=eno16777736
ONBOOT=yes
BRIDGE=br0
# vi ifcfg-br0
DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
ONBOOT=yes
DELAY=0
STP=yes
IPADDR=192.168.1.144
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS=114.114.114.114
3、重启相关服务,以及关闭相关服务
# systemctl stop NetworkManager
# systemctl disable NetworkManager
# systemctl restart network
br0正常启动,能够正常访问该机器即可,再用下面命令查看有即可:
# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000c29ebab05 yes eno16777736
4、修改docker配置文件,修改桥接的网卡以及IP分配范围
# vim /etc/sysconfig/docker
将:
OPTIONS='--selinux-enabled'
修改为:
OPTIONS='--selinux-enabled -b=br0 --fixed-cidr=192.168.1.192/26'
重新启动docker
# systemctl stop docker.service
# systemctl start docker.service
5、启动docker实例
# docker run -i -t centos /bin/bash
# ip addr show eth0
23: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
link/ether 02:42:c0:a8:01:c6 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.193/24 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::42:c0ff:fea8:1c6/64 scope link
valid_lft forever preferred_lft forever