Docker 安装配置
Centos 6.x 安装
https://dl.fedoraproject.org/pub/epel/6Server/x86_64/docker-io-1.7.1-2.el6.x86_64.rpm
安装 rpm
关闭 seLinux
1
2setenforce 0
sed -i '/^SELINUX=/c\SELINUX=disabled' /etc/selinux/config使用 sohu 源安装
1
2rpm -ivh https://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm
sed -i 's/^mirrorlist=https/mirrorlist=http/' /etc/yum.repos.d/epel.repo或者使用 fedora-epel 安装
1
yum install -y https://dl.fedoraproject.org/pub/epel/6Server/x86_64/epel-release-6-8.noarch.rpm
安装 docker-io
1
yum install -y docker-io
启动 docker
1
service docker start
修改 docker 默认 IP 段
docker 启动时默认使用 172.17.x.x 作为容器的 ip 地址
1
2
3service docker stop
ip link set docker0 down
brctl delbr docker0修改/etc/sysconfig/docker 文件 添加-bip 参数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16# /etc/sysconfig/docker
#
# Other arguments to pass to the docker daemon process
# These will be parsed by the sysv initscript and appended
# to the arguments list passed to docker -d
other_args=-bip=172.16.10.1/24
DOCKER_CERT_PATH=/etc/docker
# Resolves: rhbz#1176302 (docker issue #407)
DOCKER_NOWARN_KERNEL_VERSION=1
# Location used for temporary files, such as those created by
# # docker load and build operations. Default is /var/lib/docker/tmp
# # Can be overriden by setting the following environment variable.
# # DOCKER_TMPDIR=/var/tmp
Docker 网络配置
Centos 默认配置文件位置 /etc/sysconfig/docker
docker 默认添加 docker0 网桥
修改 docker0 IP
1 | ifconfig docker0 172.12.10.1 netmask 255.255.255.0 up |
添加 linux 网桥
1 | vim /etc/sysconfig/network-scripts/ifcfg-br0 |
1 | DEVICE="br0" |
1 | vim /etc/sysconfig/network-scripts/ifcfg-eth0 |
1 | DEVICE=eth0 |
1 | service network restart |
修改 Docker 默认配置
1 | vim /etc/sysconfig/docker |
1 | # /etc/sysconfig/docker |
service docker restart 重启使用设置生效(使用 br0 网桥)
使用 brctl 命令
查看网桥
1 | brctl show |
1 | [root@localhost hadoop-cluster-docker]# brctl show |
添加网桥
1 | brctl addbr |
删除网桥
1 | brctl delbr |
brctl addif
brctl delif
设置网桥生效
1 | ip link set dev br0 up |
设置网桥失效
1 | ip link set dev docker0 down |
ip addr 查看信息
1 | ip addr |
brctl 创建临时网桥
1 | brctl addbr br1 |
设置网桥地址并生效
1 | ifconfig br1 192.168.56.111 netmask 255.255.255.0 up |
将网卡设备 eth0 加入网桥
1 | brctl addif br1 eth0 |
pipework 设置 docker 静态 ip
docker 启动指定网络自定
1 | docker run --net=none |
1 | wget https://github.com/jpetazzo/pipework/archive/master.zip |
1 | unzip master.zip |
1 | cd pipework-master/ |
1 | cp pipework /usr/local/bin/ |
pipework 网桥 容器 id IP/24@GATEWAY
1 | pipework br0 abc 192.168.56.200/[email protected] |