阿里云上CentOS 6.x安装Docker

我在阿里云上托管的一台服务器,CentOS版本比较老,要安装docker,版本太低CentOS 6.5不行,所以先升级到CentOS 6.9,过程比较曲折,反正最后是升级成功了:

1
2
[ayserver ~]# cat /etc/issue
CentOS release 6.9 (Final)

关键是内核版本,现在是2.6.32,已经符合安装docker的条件:

1
2
[ayserver ~]# uname -a
Linux ayserver 2.6.32-696.6.3.el6.x86_64

导入fedora的源,导入失败,提示已经有6.8版本的了:

1
2
3
4
[ayserver ~]# rpm -ivfh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
Retrieving https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
Preparing... ########################################### [100%]
package epel-release-6-8.noarch is already installed

准备先删除epel源,提示有依赖:

1
2
3
4
[ayserver ~]# rpm -ef epel-release
error: Failed dependencies:
epel-release = 6 is needed by (installed) ius-release-1.0-14.ius.centos6.noarch
epel-release >= 6 is needed by (installed) remi-release-6.6-1.el6.remi.noarch

于是将依赖先删除,再删除epel,成功:

1
2
3
4
5
6
7
8
9
10
11
12
[ayserver ~]# rpm -ef ius-release
warning: erase unlink of /etc/yum.repos.d/ius.repo failed: No such file or directory
warning: erase unlink of /etc/yum.repos.d/ius-testing.repo failed: No such file or directory
warning: erase unlink of /etc/yum.repos.d/ius-dev.repo failed: No such file or directory
warning: erase unlink of /etc/yum.repos.d/ius-archive.repo failed: No such file or directory
[ayserver ~]# rpm -ef remi-release
warning: erase unlink of /etc/yum.repos.d/remi.repo failed: No such file or directory
warning: erase unlink of /etc/yum.repos.d/remi-safe.repo failed: No such file or directory
warning: erase unlink of /etc/yum.repos.d/remi-php70.repo failed: No such file or directory
[ayserver ~]# rpm -ef epel-release
warning: erase unlink of /etc/yum.repos.d/epel.repo failed: No such file or directory
warning: erase unlink of /etc/yum.repos.d/epel-testing.repo failed: No such file or directory

再次导入fedora最新源,成功:

1
2
3
4
5
[ayserver ~]# rpm -ivfh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
Retrieving https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
Preparing... ########################################### [100%]
1:epel-release ########################################### [100%]
[ayserver ~]# yum makecache

有docker-ce也有docker-io,发现docker-ce依赖比较新,装不上,于是安装docker-io,没研究这两个有什么区别。

1
[ayserver ~]# yum info docker-io

安装好后,启动失败:

1
2
3
4
5
6
[ayserver ~]# docker -d
WARN[0000] You are running linux kernel version 2.6.32-696.6.3.el6.x86_64, which might be unstable running docker. Please upgrade your kernel to 3.10.0.
INFO[0000] Listening for HTTP on unix (/var/run/docker.sock)
INFO[0000] [graphdriver] using prior storage driver "devicemapper"
WARN[0000] Running modprobe bridge nf_nat failed with message: , error: exit status 1
FATA[0000] Error starting daemon: Error initializing network controller: Error creating default "bridge" network: can't find an address range for interface "docker0"

这又是什么问题?看看路由表:

1
2
3
4
[ayserver ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.16.0.0 10.144.175.247 255.240.0.0 UG 0 0 0 eth0

docker默认使用的172.16网段,居然已经存在路由表里面,那是阿里自己预留的网段,于是咱们需要重新给docker设置一个网段,编辑/etc/sysconfig/docker,修改other_args,添加一个新网段,例如:

1
other_args=-bip=192.168.100.1/24

启动成功:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[ayserver ~]# /etc/init.d/docker start
Starting docker: [ OK ]
[ayserver ~]# docker info
Containers: 0
Images: 0
Storage Driver: devicemapper
Pool Name: docker-202:1-1139788-pool
Pool Blocksize: 65.54 kB
Backing Filesystem: extfs
Data file: /dev/loop0
Metadata file: /dev/loop1
Metadata Space Used: 729.1 kB
Metadata Space Total: 2.147 GB
Metadata Space Available: 2.147 GB
Udev Sync Supported: true
Deferred Removal Enabled: false
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.117-RHEL6 (2016-12-13)
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 2.6.32-696.6.3.el6.x86_64