CentOS 6.8 安装 Docker

由于安装Docker时,Docker支持

  • CentOS 7 (64-bit)
  • CentOS 6.5 (64-bit) 或更高的版本

Docker 运行在 CentOS 7 上,要求系统为64位、系统内核版本为 3.10 以上。
Docker 运行在 CentOS-6.5 或更高的版本的 CentOS 上,要求系统为64位、系统内核版本为 2.6.32-431 或者更高版本

CentOS 7 的内核一般都是3.10的,而CentOS 6.X 的内核一般都是2.6,在2.6的内核下,Docker运行会比较卡,所以一般会选择升级到3.10版本。

升级内核的方式,网上有很多方法是下载内核然后编译,这样需要安装很多必备的环境和工具,比较麻烦,但是也有助于我们了解内核的编译

编译内核方式升级:
https://segmentfault.com/a/1190000000733628#articleHeader13

1. 查看当前内核版本

[root@localhost ~]# more /etc/issue
CentOS release 6.5 (Final)
Kernel \r on an \m
[root@localhost ~]# uname -a
Linux localhost.localdomain 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
  
  

    2. 导入public key

    [root@localhost ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
      
      
    • 1

    3. 安装ELRepo到CentOS

    可以去http://elrepo.org/tiki/tiki-index.php 选择要安装的ELRepo
    这里写图片描述

    [root@localhost ~]# yum install https://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm
      
      
    • 1

    4. 安装 kernel-lt(lt=long-term)

    [root@localhost ~]# yum --enablerepo=elrepo-kernel install kernel-lt -y
      
      
    • 1

    或者 安装kernel-ml(ml=mainline)

    [root@localhost ~]# yum --enablerepo=elrepo-kernel install kernel-ml -y
      
      
    • 1

    5. 编辑grub.conf文件,修改Grub引导顺序

    [root@localhost ~]# vim /etc/grub.conf
      
      
    • 1

    这里写图片描述

    因为一般新安装的内核在第一个位置,所以设置default=0,表示启动新内核

    6. 重启

    查看此时内核版本:

    [root@localhost ~]# uname -r
    3.10.105-1.el6.elrepo.x86_64
      
      
    • 1
    • 2

    成功!

    2. 安装docker-io

    [root@localhost ~]# yum install docker-io
      
      

    如何显示没有该package,则先执行下面这条指令,安装yum源:

    [root@localhost ~]# yum -y install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
      
      

    如果执行命令 yum -y install docker-io 和 命令 yum -y install docker报:
    已加载插件:fastestmirror, refresh-packagekit, security
    设置安装进程
    Loading mirror speeds from cached hostfile

    还没有解决之前,我看了网上的两解决办法
    1.yum没有找到docker包,更新epel第三方软件库,运行命令:sudo yum install epel-release ,之后再执行:sudo yum install docker
    爽!上面的可行!

    2.直接用下载源安装,执行命令:yum install https://get.docker.com/rpm/1.7.1/centos-6/RPMS/x86_64/docker-engine-1.7.1-1.el6.x86_64.rpm

    其中tm的注意啦,在没有用第二种的情况下,执行docker命令会提示【docker: 未被识别的服务】,而且根据网上说的更改配置文件执行
    vi /etc/sysconfig/docker
    是没有用滴,因为不存在!
    终于百度到了,安装docker的时候要执行 yum -y install docker-io 而不是 yum -y install docker!!!!

    最后mark一波。。详细一点的文章连接 http://blog.csdn.net/yushl_sirius/article/details/76499890

    后来,又有问题啦,嘿嘿
    执行完 yum -y install docker-io 之后,再执行docker , 提示:Segmentation Fault or Critical Error encountered. Dumping core and aborting
    往上一看发现=======0.0…
    事务测试出错:
    file /usr/bin/docker from install of docker-io-1.7.1-2.el6.x86_64 conflicts with file from package docker-1.5-5.el6.x86_64
    这个是重复安装的冲突,原因,安装了docker之后再安装docker-io
    解决方式:先执行 yum remove docker 后再 yum install docker-io 即可。
    最后执行一波:
    $ docker 回车!

    安装完成界面:

    这里写图片描述

    3. Docker操作

    查看Docker版本信息

    [root@localhost ~]# docker version
    Client version: 1.7.1
    Client API version: 1.19
    Go version (client): go1.4.2
    Git commit (client): 786b29d/1.7.1
    OS/Arch (client): linux/amd64
    Get http:///var/run/docker.sock/v1.19/version: dial unix /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?
    
      
      
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    启动Docker

    [root@localhost ~]# service docker start
      
      
    • 1

    查看Docker日志

    [root@localhost ~]# cat /var/log/docker
      
      
    • 1

    停止Docker

    [root@localhost ~]# service docker stop
      
      
    • 1

    4. 卸载Docker

    4.1 查看安装的Docker包

    [root@localhost ~]# yum list installed | grep docker
    docker-io.x86_64        1.7.1-2.el6     @epel 
      
      
    • 1
    • 2

    4.2 yum 卸载 Docker

    [root@localhost ~]# yum -y remove docker-io.x86_64
      
      
    • 1

    4.2 删除Docker镜像

    [root@localhost ~]# rm -rf /var/lib/docker
      
      
    • 1

    更多Docker的使用指南:http://www.runoob.com/docker/docker-tutorial.html

    猜你喜欢

    转载自blog.csdn.net/qq_40597878/article/details/89455834