0%

Docker安装配置

Docker 安装配置

Centos 6.x 安装

https://dl.fedoraproject.org/pub/epel/6Server/x86_64/docker-io-1.7.1-2.el6.x86_64.rpm

  1. 安装 rpm

    关闭 seLinux

    1
    2
    setenforce 0
    sed -i '/^SELINUX=/c\SELINUX=disabled' /etc/selinux/config

    使用 sohu 源安装

    1
    2
    rpm -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
  2. 安装 docker-io

    1
    yum install -y docker-io
  3. 启动 docker

    1
    service docker start
  4. 修改 docker 默认 IP 段

    docker 启动时默认使用 172.17.x.x 作为容器的 ip 地址

    1
    2
    3
    service 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
2
3
4
5
6
ifconfig docker0 172.12.10.1 netmask 255.255.255.0 up

ip link set dev docker0 down 停用docker0
ip link set dev docker0 up 启用docker0

brctl delbr docker0 删除docker0(service docker restart 后自动创建)

添加 linux 网桥

1
vim /etc/sysconfig/network-scripts/ifcfg-br0
1
2
3
4
5
6
7
DEVICE="br0"
ONBOOT="yes"
TYPE="Bridge"
BOOTPROTO=static
IPADDR=192.168.88.30
NETMASK=255.255.0.0
GATEWAY=192.168.88.1
1
vim /etc/sysconfig/network-scripts/ifcfg-eth0
1
2
3
4
5
6
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
BRIDGE="br0"
1
service network restart

修改 Docker 默认配置

1
vim /etc/sysconfig/docker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# /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=-b=br0
#other_args=
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

service docker restart 重启使用设置生效(使用 br0 网桥)

使用 brctl 命令
查看网桥

1
brctl show
1
2
3
4
5
6
[root@localhost hadoop-cluster-docker]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.82edf9468ced no eth0
veth1pl12684
veth1pl12880
veth1pl13068

添加网桥

1
brctl addbr

删除网桥

1
brctl delbr

brctl addif add interface to bridge
brctl delif delete interface from bridge

设置网桥生效

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]