QQ叫紫珊 发表于 2019-2-15 14:04:10

docker实战centos 7.4 安装docker

docker实战centos 7.4 安装docker
  首发:arppinging

一、docker安装条件
  1.64 bit cpu
2.linux kernel 3.10+
3.linux kernel 支持 cgroups and namespaces
  centos 7.4 x64为的满足条件。实际上centos 6.x系列也能安装docker。

二、下载和安装yum源
  下载yum文件

# wget https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
  修改yum文件,因为yum文件中的地址为docker官方地址,下载比较慢
  vim中替换网址为清华的地址:

%s@https://download.docker.com/@https://mirrors.tuna.tsinghua.edu.cn/docker-ce/@
  yum repolist查看

# yum repolist
已加载插件:fastestmirror, langpacks
base                                                                                                                                                                                                                                                   | 3.6 kB00:00:00   
docker-ce-stable                                                                                                                                                                                                                                       | 3.5 kB00:00:00   
extras                                                                                                                                                                                                                                                 | 3.4 kB00:00:00   
updates                                                                                                                                                                                                                                                | 3.4 kB00:00:00   
zabbix                                                                                                                                                                                                                                                 | 2.9 kB00:00:00   
zabbix-non-supported                                                                                                                                                                                                                                 |951 B00:00:00   
(1/6): base/7/x86_64/group_gz                                                                                                                                                                                                                        | 166 kB00:00:01   
(2/6): updates/7/x86_64/primary_db                                                                                                                                                                                                                     | 1.3 MB00:00:00   
(3/6): extras/7/x86_64/primary_db                                                                                                                                                                                                                      | 153 kB00:00:01   
(4/6): base/7/x86_64/primary_db                                                                                                                                                                                                                        | 6.0 MB00:00:01   
(5/6): docker-ce-stable/x86_64/primary_db                                                                                                                                                                                                            |19 kB00:00:02   
(6/6): docker-ce-stable/x86_64/updateinfo                                                                                                                                                                                                            |   55 B00:00:03   
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* extras: mirrors.cn99.com
* updates: mirrors.cn99.com
源标识                                                                                                                   源名称                                                                                                                                       状态
base/7/x86_64                                                                                                            CentOS-7 - Base                                                                                                                              10,019
docker-ce-stable/x86_64                                                                                                Docker CE Stable - x86_64                                                                                                                        25
extras/7/x86_64                                                                                                          CentOS-7 - Extras                                                                                                                                 312
updates/7/x86_64                                                                                                         CentOS-7 - Updates                                                                                                                              574
zabbix/x86_64                                                                                                            Zabbix Official Repository - x86_64                                                                                                               236
zabbix-non-supported/x86_64                                                                                              Zabbix Official Repository non-supported - x86_64                                                                                                   4
repolist: 11,170
  可以看到有docker-ce了。docker现有两个版本,一个是付费的商业版(docker-ee),一个是免费的社区版(docker-ce)

三、安装docker

# yum install docker-ce -y
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* extras: mirrors.cn99.com
* updates: mirrors.cn99.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 docker-ce.x86_64.3.18.09.0-3.el7 将被 安装
--> 正在处理依赖关系 container-selinux >= 2.9,它被软件包 3:docker-ce-18.09.0-3.el7.x86_64 需要
--> 正在处理依赖关系 containerd.io,它被软件包 3:docker-ce-18.09.0-3.el7.x86_64 需要
--> 正在处理依赖关系 docker-ce-cli,它被软件包 3:docker-ce-18.09.0-3.el7.x86_64 需要
--> 正在检查事务
---> 软件包 container-selinux.noarch.2.2.74-1.el7 将被 安装
--> 正在处理依赖关系 selinux-policy-targeted >= 3.13.1-216.el7,它被软件包 2:container-selinux-2.74-1.el7.noarch 需要
--> 正在处理依赖关系 selinux-policy-base >= 3.13.1-216.el7,它被软件包 2:container-selinux-2.74-1.el7.noarch 需要
--> 正在处理依赖关系 selinux-policy >= 3.13.1-216.el7,它被软件包 2:container-selinux-2.74-1.el7.noarch 需要
---> 软件包 containerd.io.x86_64.0.1.2.0-3.el7 将被 安装
---> 软件包 docker-ce-cli.x86_64.1.18.09.0-3.el7 将被 安装
--> 正在检查事务
---> 软件包 selinux-policy.noarch.0.3.13.1-166.el7 将被 升级
---> 软件包 selinux-policy.noarch.0.3.13.1-229.el7_6.6 将被 更新
--> 正在处理依赖关系 policycoreutils >= 2.5-24,它被软件包 selinux-policy-3.13.1-229.el7_6.6.noarch 需要
--> 正在处理依赖关系 libsemanage >= 2.5-13,它被软件包 selinux-policy-3.13.1-229.el7_6.6.noarch 需要
---> 软件包 selinux-policy-targeted.noarch.0.3.13.1-166.el7 将被 升级
---> 软件包 selinux-policy-targeted.noarch.0.3.13.1-229.el7_6.6 将被 更新
--> 正在检查事务
---> 软件包 libsemanage.x86_64.0.2.5-8.el7 将被 升级
--> 正在处理依赖关系 libsemanage = 2.5-8.el7,它被软件包 libsemanage-python-2.5-8.el7.x86_64 需要
---> 软件包 libsemanage.x86_64.0.2.5-14.el7 将被 更新
--> 正在处理依赖关系 libsepol >= 2.5-10,它被软件包 libsemanage-2.5-14.el7.x86_64 需要
--> 正在处理依赖关系 libselinux >= 2.5-14,它被软件包 libsemanage-2.5-14.el7.x86_64 需要
---> 软件包 policycoreutils.x86_64.0.2.5-17.1.el7 将被 升级
--> 正在处理依赖关系 policycoreutils = 2.5-17.1.el7,它被软件包 policycoreutils-python-2.5-17.1.el7.x86_64 需要
---> 软件包 policycoreutils.x86_64.0.2.5-29.el7 将被 更新
--> 正在处理依赖关系 libselinux-utils >= 2.5-14,它被软件包 policycoreutils-2.5-29.el7.x86_64 需要
--> 正在检查事务
---> 软件包 libselinux.x86_64.0.2.5-11.el7 将被 升级
--> 正在处理依赖关系 libselinux(x86-64) = 2.5-11.el7,它被软件包 libselinux-python-2.5-11.el7.x86_64 需要
---> 软件包 libselinux.x86_64.0.2.5-14.1.el7 将被 更新
---> 软件包 libselinux-utils.x86_64.0.2.5-11.el7 将被 升级
---> 软件包 libselinux-utils.x86_64.0.2.5-14.1.el7 将被 更新
---> 软件包 libsemanage-python.x86_64.0.2.5-8.el7 将被 升级
---> 软件包 libsemanage-python.x86_64.0.2.5-14.el7 将被 更新
---> 软件包 libsepol.x86_64.0.2.5-6.el7 将被 升级
---> 软件包 libsepol.x86_64.0.2.5-10.el7 将被 更新
---> 软件包 policycoreutils-python.x86_64.0.2.5-17.1.el7 将被 升级
---> 软件包 policycoreutils-python.x86_64.0.2.5-29.el7 将被 更新
--> 正在处理依赖关系 setools-libs >= 3.3.8-4,它被软件包 policycoreutils-python-2.5-29.el7.x86_64 需要
--> 正在检查事务
---> 软件包 libselinux-python.x86_64.0.2.5-11.el7 将被 升级
---> 软件包 libselinux-python.x86_64.0.2.5-14.1.el7 将被 更新
---> 软件包 setools-libs.x86_64.0.3.3.8-1.1.el7 将被 升级
---> 软件包 setools-libs.x86_64.0.3.3.8-4.el7 将被 更新
--> 解决依赖关系完成
依赖关系解决
==============================================================================================================================================================================================================================================================================
Package                                                                  架构                                                    版本                                                                源                                                               大小
==============================================================================================================================================================================================================================================================================
正在安装:
docker-ce                                                                x86_64                                                3:18.09.0-3.el7                                                   docker-ce-stable                                                   19 M
为依赖而安装:
container-selinux                                                      noarch                                                2:2.74-1.el7                                                      extras                                                             38 k
containerd.io                                                            x86_64                                                1.2.0-3.el7                                                         docker-ce-stable                                                   22 M
docker-ce-cli                                                            x86_64                                                1:18.09.0-3.el7                                                   docker-ce-stable                                                   14 M
为依赖而更新:
libselinux                                                               x86_64                                                2.5-14.1.el7                                                      base                                                            162 k
libselinux-python                                                      x86_64                                                2.5-14.1.el7                                                      base                                                            235 k
libselinux-utils                                                         x86_64                                                2.5-14.1.el7                                                      base                                                            151 k
libsemanage                                                            x86_64                                                2.5-14.el7                                                          base                                                            151 k
libsemanage-python                                                       x86_64                                                2.5-14.el7                                                          base                                                            113 k
libsepol                                                               x86_64                                                2.5-10.el7                                                          base                                                            297 k
policycoreutils                                                          x86_64                                                2.5-29.el7                                                          base                                                            916 k
policycoreutils-python                                                   x86_64                                                2.5-29.el7                                                          base                                                            456 k
selinux-policy                                                         noarch                                                3.13.1-229.el7_6.6                                                updates                                                         483 k
selinux-policy-targeted                                                noarch                                                3.13.1-229.el7_6.6                                                updates                                                         6.9 M
setools-libs                                                             x86_64                                                3.3.8-4.el7                                                         base                                                            620 k
事务概要
==============================================================================================================================================================================================================================================================================
安装1 软件包 (+ 3 依赖软件包)
升级         ( 11 依赖软件包)
总下载量:65 M
Downloading packages:
No Presto metadata available for base
updates/7/x86_64/prestodelta                                                                                                                                                                                                                           | 169 kB00:00:01   
(1/15): container-selinux-2.74-1.el7.noarch.rpm                                                                                                                                                                                                      |38 kB00:00:00   
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-18.09.0-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY================================                                                       ] 5.6 MB/s |33 MB00:00:05 ETA
docker-ce-18.09.0-3.el7.x86_64.rpm 的公钥尚未安装
(2/15): docker-ce-18.09.0-3.el7.x86_64.rpm                                                                                                                                                                                                             |19 MB00:00:04   
(3/15): libselinux-2.5-14.1.el7.x86_64.rpm                                                                                                                                                                                                             | 162 kB00:00:00   
(4/15): libselinux-utils-2.5-14.1.el7.x86_64.rpm                                                                                                                                                                                                       | 151 kB00:00:00   
(5/15): libsemanage-2.5-14.el7.x86_64.rpm                                                                                                                                                                                                            | 151 kB00:00:00   
(6/15): libsemanage-python-2.5-14.el7.x86_64.rpm                                                                                                                                                                                                       | 113 kB00:00:00   
(7/15): libsepol-2.5-10.el7.x86_64.rpm                                                                                                                                                                                                               | 297 kB00:00:00   
(8/15): policycoreutils-2.5-29.el7.x86_64.rpm                                                                                                                                                                                                          | 916 kB00:00:00   
(9/15): libselinux-python-2.5-14.1.el7.x86_64.rpm                                                                                                                                                                                                      | 235 kB00:00:00   
(10/15): selinux-policy-3.13.1-229.el7_6.6.noarch.rpm                                                                                                                                                                                                | 483 kB00:00:00   
(11/15): containerd.io-1.2.0-3.el7.x86_64.rpm                                                                                                                                                                                                          |22 MB00:00:06   
(12/15): setools-libs-3.3.8-4.el7.x86_64.rpm                                                                                                                                                                                                         | 620 kB00:00:00   
(13/15): selinux-policy-targeted-3.13.1-229.el7_6.6.noarch.rpm                                                                                                                                                                                       | 6.9 MB00:00:02   
(14/15): docker-ce-cli-18.09.0-3.el7.x86_64.rpm                                                                                                                                                                                                      |14 MB00:00:02   
(15/15): policycoreutils-python-2.5-29.el7.x86_64.rpm                                                                                                                                                                                                | 456 kB00:00:02   
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                                                                                                                          8.0 MB/s |65 MB00:00:08   
从 https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg 检索密钥
导入 GPG key 0x621E9F35:
用户ID   : "Docker Release (CE rpm) "
指纹       : 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
来自       : https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在更新    : libsepol-2.5-10.el7.x86_64                                                                                                                                                                                                                               1/26
正在更新    : libselinux-2.5-14.1.el7.x86_64                                                                                                                                                                                                                           2/26
正在更新    : libsemanage-2.5-14.el7.x86_64                                                                                                                                                                                                                            3/26
正在更新    : libselinux-utils-2.5-14.1.el7.x86_64                                                                                                                                                                                                                     4/26
正在更新    : policycoreutils-2.5-29.el7.x86_64                                                                                                                                                                                                                        5/26
正在更新    : selinux-policy-3.13.1-229.el7_6.6.noarch                                                                                                                                                                                                               6/26
正在安装    : containerd.io-1.2.0-3.el7.x86_64                                                                                                                                                                                                                         7/26
正在安装    : 1:docker-ce-cli-18.09.0-3.el7.x86_64                                                                                                                                                                                                                     8/26
正在更新    : selinux-policy-targeted-3.13.1-229.el7_6.6.noarch                                                                                                                                                                                                      9/26
正在更新    : libsemanage-python-2.5-14.el7.x86_64                                                                                                                                                                                                                  10/26
正在更新    : setools-libs-3.3.8-4.el7.x86_64                                                                                                                                                                                                                         11/26
正在更新    : libselinux-python-2.5-14.1.el7.x86_64                                                                                                                                                                                                                   12/26
正在更新    : policycoreutils-python-2.5-29.el7.x86_64                                                                                                                                                                                                                13/26
正在安装    : 2:container-selinux-2.74-1.el7.noarch                                                                                                                                                                                                                   14/26
setsebool:SELinux is disabled.
正在安装    : 3:docker-ce-18.09.0-3.el7.x86_64                                                                                                                                                                                                                        15/26
清理      : selinux-policy-targeted-3.13.1-166.el7.noarch                                                                                                                                                                                                         16/26
清理      : policycoreutils-python-2.5-17.1.el7.x86_64                                                                                                                                                                                                            17/26
清理      : selinux-policy-3.13.1-166.el7.noarch                                                                                                                                                                                                                  18/26
清理      : policycoreutils-2.5-17.1.el7.x86_64                                                                                                                                                                                                                     19/26
清理      : libselinux-utils-2.5-11.el7.x86_64                                                                                                                                                                                                                      20/26
清理      : setools-libs-3.3.8-1.1.el7.x86_64                                                                                                                                                                                                                     21/26
清理      : libselinux-python-2.5-11.el7.x86_64                                                                                                                                                                                                                     22/26
清理      : libsemanage-python-2.5-8.el7.x86_64                                                                                                                                                                                                                     23/26
清理      : libsemanage-2.5-8.el7.x86_64                                                                                                                                                                                                                            24/26
清理      : libselinux-2.5-11.el7.x86_64                                                                                                                                                                                                                            25/26
清理      : libsepol-2.5-6.el7.x86_64                                                                                                                                                                                                                               26/26
验证中      : 3:docker-ce-18.09.0-3.el7.x86_64                                                                                                                                                                                                                         1/26
验证中      : selinux-policy-3.13.1-229.el7_6.6.noarch                                                                                                                                                                                                               2/26
验证中      : 2:container-selinux-2.74-1.el7.noarch                                                                                                                                                                                                                  3/26
验证中      : policycoreutils-2.5-29.el7.x86_64                                                                                                                                                                                                                        4/26
验证中      : setools-libs-3.3.8-4.el7.x86_64                                                                                                                                                                                                                        5/26
验证中      : 1:docker-ce-cli-18.09.0-3.el7.x86_64                                                                                                                                                                                                                     6/26
验证中      : libsemanage-python-2.5-14.el7.x86_64                                                                                                                                                                                                                     7/26
验证中      : containerd.io-1.2.0-3.el7.x86_64                                                                                                                                                                                                                         8/26
验证中      : libsemanage-2.5-14.el7.x86_64                                                                                                                                                                                                                            9/26
验证中      : libsepol-2.5-10.el7.x86_64                                                                                                                                                                                                                              10/26
验证中      : libselinux-python-2.5-14.1.el7.x86_64                                                                                                                                                                                                                   11/26
验证中      : selinux-policy-targeted-3.13.1-229.el7_6.6.noarch                                                                                                                                                                                                       12/26
验证中      : libselinux-utils-2.5-14.1.el7.x86_64                                                                                                                                                                                                                  13/26
验证中      : policycoreutils-python-2.5-29.el7.x86_64                                                                                                                                                                                                                14/26
验证中      : libselinux-2.5-14.1.el7.x86_64                                                                                                                                                                                                                        15/26
验证中      : libselinux-utils-2.5-11.el7.x86_64                                                                                                                                                                                                                      16/26
验证中      : libselinux-2.5-11.el7.x86_64                                                                                                                                                                                                                            17/26
验证中      : libsepol-2.5-6.el7.x86_64                                                                                                                                                                                                                               18/26
验证中      : selinux-policy-3.13.1-166.el7.noarch                                                                                                                                                                                                                  19/26
验证中      : policycoreutils-2.5-17.1.el7.x86_64                                                                                                                                                                                                                     20/26
验证中      : libsemanage-python-2.5-8.el7.x86_64                                                                                                                                                                                                                     21/26
验证中      : libsemanage-2.5-8.el7.x86_64                                                                                                                                                                                                                            22/26
验证中      : libselinux-python-2.5-11.el7.x86_64                                                                                                                                                                                                                     23/26
验证中      : policycoreutils-python-2.5-17.1.el7.x86_64                                                                                                                                                                                                            24/26
验证中      : selinux-policy-targeted-3.13.1-166.el7.noarch                                                                                                                                                                                                         25/26
验证中      : setools-libs-3.3.8-1.1.el7.x86_64                                                                                                                                                                                                                     26/26
已安装:
docker-ce.x86_64 3:18.09.0-3.el7                                                                                                                                                                                                                                          
作为依赖被安装:
container-selinux.noarch 2:2.74-1.el7                                                      containerd.io.x86_64 0:1.2.0-3.el7                                                      docker-ce-cli.x86_64 1:18.09.0-3.el7                                                   
作为依赖被升级:
libselinux.x86_64 0:2.5-14.1.el7      libselinux-python.x86_64 0:2.5-14.1.el7      libselinux-utils.x86_64 0:2.5-14.1.el7         libsemanage.x86_64 0:2.5-14.el7                         libsemanage-python.x86_64 0:2.5-14.el7   libsepol.x86_64 0:2.5-10.el7   
policycoreutils.x86_64 0:2.5-29.el7   policycoreutils-python.x86_64 0:2.5-29.el7   selinux-policy.noarch 0:3.13.1-229.el7_6.6   selinux-policy-targeted.noarch 0:3.13.1-229.el7_6.6   setools-libs.x86_64 0:3.3.8-4.el7         
完毕!
#
四、配置网络加速器
  这里我配置的是官网的加速器,大家可以配置和阿里云的加速器,比较快。

mkdir /etc/docker
vim /etc/docker/daemon.json
{
"registry-mirrors":["https://registry.docker-cn.com"]
}
  如果加速文件配置不正确,启动服务时会报错

# systemctl status docker.service
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: failed (Result: start-limit) since 二 2018-12-04 21:45:06 CST; 1min 30s ago
Docs: https://docs.docker.com
Process: 19030 ExecStart=/usr/bin/dockerd -H unix:// (code=exited, status=1/FAILURE)
Main PID: 19030 (code=exited, status=1/FAILURE)
12月 04 21:45:04 node1.weide.com systemd: Unit docker.service entered failed state.
12月 04 21:45:04 node1.weide.com systemd: docker.service failed.
12月 04 21:45:06 node1.weide.com systemd: docker.service holdoff time over, scheduling restart.
12月 04 21:45:06 node1.weide.com systemd: start request repeated too quickly for docker.service
12月 04 21:45:06 node1.weide.com systemd: Failed to start Docker Application Container Engine.
12月 04 21:45:06 node1.weide.com systemd: Unit docker.service entered failed state.
12月 04 21:45:06 node1.weide.com systemd: docker.service failed.
12月 04 21:45:09 node1.weide.com systemd: start request repeated too quickly for docker.service
12月 04 21:45:09 node1.weide.com systemd: Failed to start Docker Application Container Engine.
12月 04 21:45:09 node1.weide.com systemd: docker.service failed.
五、启动docker进程
  启动docker 守护进程

    systemctl start docker.service
  查看docker版本

    docker version
# docker version
Client:
Version:         18.09.0
API version:       1.39
Go version:      go1.10.4
Git commit:      4d60db4
Built:             Wed Nov7 00:48:22 2018
OS/Arch:         linux/amd64
Experimental:      false
Server: Docker Engine - Community
Engine:
Version:          18.09.0
API version:      1.39 (minimum version 1.12)
Go version:       go1.10.4
Git commit:       4d60db4
Built:            Wed Nov7 00:19:08 2018
OS/Arch:          linux/amd64
Experimental:   false
#
  查看docker详细信息

    # docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 18.09.0
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: c4446665cb9c30056f4998ed953e6d4ff22c7c39
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-693.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 7.64GiB
Name: node1.weide.com
ID: PHWK:UCCE:5GB6:WS7I:EAWC:6Q4J:GXQF:A5KJ:ZWXG:JEUO:YE5Z:QU6C
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
https://registry.docker-cn.com/
Live Restore Enabled: false
Product License: Community Engine
#


页: [1]
查看完整版本: docker实战centos 7.4 安装docker