CentOS 6.9安装Docker


由于Docker要求运行的linux内核版本为3.8以上,因此,在安装之前,要查看一下宿主机操作系统的内核版本,否则如果是内核低于3.8,能够成功安装Docker,但进入Docker后,会自动退出。

1、下载安装CentOS 6.9

CentOS 6 系列,最新版本为6.9,由于 Docker 只能运行在64位系统上,因此到CentOS的官网上选择某个镜像 下载  CentOS 6.9 64位

2、升级CentOS的Linux内核

CentOS 6.9默认的linux内核版本为2.6,CentOS 7默认的linux内核版本为3.10,因此,对于CentOS 6.9则需进行内核版本的升级

1)进入更新linux内核的网址  http://elrepo.org/tiki/tiki-index.php

2)按照操作指引进行内核更新,在root账号下执行以下指令

(1)导入 public key

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

(2)安装ELRepo

针对Centos6,

rpm -Uvh http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm

针对Cenos7,

rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm (external link)

(3)安装kernel

长期支持的版本,稳定(推荐)

yum --enablerepo=elrepo-kernel install -y kernel-lt

主线版本(mainline)

yum --enablerepo=elrepo-kernel install -y kernel-ml

(4)修改Grub引导顺序,设置默认启动新升级的内核

编辑grub.conf文件

vi /etc/grub.conf

将 default 修改为新安装内核的位置

# grub.conf generated by anaconda
#
default=0    #一般最新安装的内核在第一个位置,将其修改为 0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (3.10.28-1.el6.elrepo.x86_64)
        root (hd0,0)
        kernel /boot/vmlinuz-3.10.28-1.el6.elrepo.x86_64 ro root=UUID=0a05411f-16f2-4d69-beb0-2db4cefd3613 rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
        initrd /boot/initramfs-3.10.28-1.el6.elrepo.x86_64.img
title CentOS (2.6.32-431.3.1.el6.x86_64)
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.32-431.3.1.el6.x86_64 ro root=UUID=0a05411f-16f2-4d69-beb0-2db4cefd3613 rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
        initrd /boot/initramfs-2.6.32-431.3.1.el6.x86_64.img

(5)重启,内核升级完成

reboot

3、安装 docker

(1)禁用 selinux

因为selinux和LXC有冲突,所以禁用掉selinux

vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
SELINUXTYPE=targeted

(2)配置Fedora EPEL 源

由于CentOS 6.x与7.x安装docker是有一些不同的,CentOS 6.x上docker的安装包叫docker-io,来源于Fedora epel库,这个仓库维护了大量的没有包含在发行版中的软件,所以先要安装EPEL,而CentOS 7.x的docker直接包含在官方镜像源的Extras仓库(CentOS-Base.repo下的[extras]节enable=1启用)

yum -y install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

(3)安装docker

安装 docker-io

yum install -y docker-io

(4)启动docker

service docker start

(5)查看docker版本

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
Server version: 1.7.1
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 786b29d/1.7.1
OS/Arch (server): linux/amd64

(6)执行docker hello-world

拉取 hello-world 镜像

docker pull hello-world

执行 hello-world

docker run hello-world
Hello from Docker.
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (Assuming it was not already locally available.)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

For more examples and ideas, visit:
 http://docs.docker.com/userguide/

出现上面的输出信息表示 Docker 已经完全安装成功了

4、卸载docker

如果要卸载docker,也非常简单,查看docker安装包

yum list installed | grep docker

然后删除安装包

yum -y remove docker-io.x86_64

删除镜像或容器

rm -rf /var/lib/docker

更多Docker相关教程见以下内容: 

Docker安装应用(CentOS 6.5_x64)  

Ubuntu 16.04 服务器上配置使用 Docker   

Ubuntu 15.04下安装Docker   

Docker 安装实例  

Docker 创建基础镜像   

在 Ubuntu 15.04 上如何安装Docker及基本用法  

Ubuntu 16.04上Docker使用手记  

使用Docker分分钟启动常用应用   

Ubuntu 16.04下Docker修改配置文件不生效解决办法   

Docker 的详细介绍:请点这里
Docker 的下载地址:请点这里

相关内容