在国内的云服务商提供的镜像内核都是2.6.*的,不能满足docker需要的3.1.*,因此首先需要升级一下内核

1
2
3
4
5
6
7
8
#导入public key
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

#安装elrepo到内核为2.6.32的CentOS中
rpm -Uvh http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm

#安装kernel-lt(long term support)长期支持版本
yum --enablerepo=elrepo-kernel install kernel-lt -y

如果yum安装的慢,可以通过rpm安装kernel-lt

1
2
访问http://elrepo.org/linux/kernel/el6/x86_64/RPMS/下载对应的rpm包,通过rpm方式安装:
rpm -ivh kernel-lt-3.10.93-1.el6.elrepo.x86_64.rpm

安装完毕后编辑配置文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
vi /etc/grub.conf

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You do not have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /, eg.
#          root (hd0,0)
#          kernel /boot/vmlinuz-version ro root=/dev/xvda1
#          initrd /boot/initrd-[generic-]version.img
#boot=/dev/xvda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (3.10.105-1.el6.elrepo.x86_64)
        root (hd0,0)
        kernel /boot/vmlinuz-3.10.105-1.el6.elrepo.x86_64 ro root=UUID=94e4e384-0ace-437f-bc96-057dd64f42ee rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
        initrd /boot/initramfs-3.10.105-1.el6.elrepo.x86_64.img
title CentOS (2.6.32-573.22.1.el6.x86_64)
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.32-573.22.1.el6.x86_64 ro root=UUID=94e4e384-0ace-437f-bc96-057dd64f42ee rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
        initrd /boot/initramfs-2.6.32-573.22.1.el6.x86_64.img
title CentOS (2.6.32-431.23.3.el6.x86_64)

我们用的 CentOS (3.10.105-1.el6.elrepo.x86_64)就排在第一个,因此改成 default=0

保存后重启系统

1
2
uname -a
Linux iZm5eib1msf1eaxvrvhp60Z 3.10.105-1.el6.elrepo.x86_64 #1 SMP Fri Feb 10 10:48:08 EST 2017 x86_64 x86_64 x86_64 GNU/Linux

安装docker

1
2
3
yum install -y docker-engine
service docker start
sudo docker version

如果出现 Cannot connect to the Docker daemon. Is 'docker -d' running on this host? 这种提示,按以下解决步骤:

  1. 执行 service docker start
  2. 加上 sudo
  3. 执行 yum upgrade device-mapper

我是执行到第三步就可以正常运行了,如果还没解决问题的话就自己找去吧

资料1-centos安装docker升级内核到3.10

资料2-github/docker/issues/11356