阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS 6.9安装Docker

154次阅读
没有评论

共计 4231 个字符,预计需要花费 11 分钟才能阅读完成。

由于 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) http://www.linuxidc.com/Linux/2014-07/104595.htm 

Ubuntu 16.04 服务器上配置使用 Docker  http://www.linuxidc.com/Linux/2017-06/145176.htm 

Ubuntu 15.04 下安装 Docker  http://www.linuxidc.com/Linux/2015-07/120444.htm 

Docker 安装实例 http://www.linuxidc.com/Linux/2017-04/142666.htm 

Docker 创建基础镜像  http://www.linuxidc.com/Linux/2017-05/144112.htm 

在 Ubuntu 15.04 上如何安装 Docker 及基本用法 http://www.linuxidc.com/Linux/2015-09/122885.htm 

Ubuntu 16.04 上 Docker 使用手记 http://www.linuxidc.com/Linux/2016-12/138490.htm 

使用 Docker 分分钟启动常用应用  http://www.linuxidc.com/Linux/2017-04/142649.htm 

Ubuntu 16.04 下 Docker 修改配置文件不生效解决办法  http://www.linuxidc.com/Linux/2017-05/143862.htm 

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

本文永久更新链接地址:http://www.linuxidc.com/Linux/2018-02/150834.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计4231字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中