1. 程式人生 > >docker實戰centos 7.4 安裝docker

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檔案

[[email protected] yum.repos.d]# wget https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo

修改yum檔案,因為yum檔案中的地址為docker官方地址,下載比較慢

vim中替換網址為清華的地址:

%[email protected]://download.docker.com/@https://mirrors.tuna.tsinghua.edu.cn/docker-ce/@

yum repolist檢視

[[email protected] yum.repos.d]# yum repolist
        已載入外掛:fastestmirror, langpacks
        base                                                                                                                                                                                                                                                   | 3.6 kB  00:00:00     
        docker-ce-stable                                                                                                                                                                                                                                       | 3.5 kB  00:00:00     
        extras                                                                                                                                                                                                                                                 | 3.4 kB  00:00:00     
        updates                                                                                                                                                                                                                                                | 3.4 kB  00:00:00     
        zabbix                                                                                                                                                                                                                                                 | 2.9 kB  00:00:00     
        zabbix-non-supported                                                                                                                                                                                                                                   |  951 B  00:00:00     
        (1/6): base/7/x86_64/group_gz                                                                                                                                                                                                                          | 166 kB  00:00:01     
        (2/6): updates/7/x86_64/primary_db                                                                                                                                                                                                                     | 1.3 MB  00:00:00     
        (3/6): extras/7/x86_64/primary_db                                                                                                                                                                                                                      | 153 kB  00:00:01     
        (4/6): base/7/x86_64/primary_db                                                                                                                                                                                                                        | 6.0 MB  00:00:01     
        (5/6): docker-ce-stable/x86_64/primary_db                                                                                                                                                                                                              |  19 kB  00:00:02     
        (6/6): docker-ce-stable/x86_64/updateinfo                                                                                                                                                                                                              |   55 B  00: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

[[email protected] yum.repos.d]# 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 kB  00:00:01     
        (1/15): container-selinux-2.74-1.el7.noarch.rpm                                                                                                                                                                                                        |  38 kB  00: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 MB  00: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 MB  00:00:04     
        (3/15): libselinux-2.5-14.1.el7.x86_64.rpm                                                                                                                                                                                                             | 162 kB  00:00:00     
        (4/15): libselinux-utils-2.5-14.1.el7.x86_64.rpm                                                                                                                                                                                                       | 151 kB  00:00:00     
        (5/15): libsemanage-2.5-14.el7.x86_64.rpm                                                                                                                                                                                                              | 151 kB  00:00:00     
        (6/15): libsemanage-python-2.5-14.el7.x86_64.rpm                                                                                                                                                                                                       | 113 kB  00:00:00     
        (7/15): libsepol-2.5-10.el7.x86_64.rpm                                                                                                                                                                                                                 | 297 kB  00:00:00     
        (8/15): policycoreutils-2.5-29.el7.x86_64.rpm                                                                                                                                                                                                          | 916 kB  00:00:00     
        (9/15): libselinux-python-2.5-14.1.el7.x86_64.rpm                                                                                                                                                                                                      | 235 kB  00:00:00     
        (10/15): selinux-policy-3.13.1-229.el7_6.6.noarch.rpm                                                                                                                                                                                                  | 483 kB  00:00:00     
        (11/15): containerd.io-1.2.0-3.el7.x86_64.rpm                                                                                                                                                                                                          |  22 MB  00:00:06     
        (12/15): setools-libs-3.3.8-4.el7.x86_64.rpm                                                                                                                                                                                                           | 620 kB  00:00:00     
        (13/15): selinux-policy-targeted-3.13.1-229.el7_6.6.noarch.rpm                                                                                                                                                                                         | 6.9 MB  00:00:02     
        (14/15): docker-ce-cli-18.09.0-3.el7.x86_64.rpm                                                                                                                                                                                                        |  14 MB  00:00:02     
        (15/15): policycoreutils-python-2.5-29.el7.x86_64.rpm                                                                                                                                                                                                  | 456 kB  00:00:02     
        ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        總計                                                                                                                                                                                                                                          8.0 MB/s |  65 MB  00:00:08     
        從 https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg 檢索金鑰
        匯入 GPG key 0x621E9F35:
         使用者ID     : "Docker Release (CE rpm) <
[email protected]
>" 指紋 : 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 完畢! [[email protected] yum.repos.d]#

四、配置網路加速器

這裡我配置的是官網的加速器,大家可以配置和阿里雲的加速器,比較快。

mkdir /etc/docker
    vim /etc/docker/daemon.json
    {
        "registry-mirrors":["https://registry.docker-cn.com"]
    }

如果加速檔案配置不正確,啟動服務時會報錯

[[email protected] yum.repos.d]# 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[1]: Unit docker.service entered failed state.
        12月 04 21:45:04 node1.weide.com systemd[1]: docker.service failed.
        12月 04 21:45:06 node1.weide.com systemd[1]: docker.service holdoff time over, scheduling restart.
        12月 04 21:45:06 node1.weide.com systemd[1]: start request repeated too quickly for docker.service
        12月 04 21:45:06 node1.weide.com systemd[1]: Failed to start Docker Application Container Engine.
        12月 04 21:45:06 node1.weide.com systemd[1]: Unit docker.service entered failed state.
        12月 04 21:45:06 node1.weide.com systemd[1]: docker.service failed.
        12月 04 21:45:09 node1.weide.com systemd[1]: start request repeated too quickly for docker.service
        12月 04 21:45:09 node1.weide.com systemd[1]: Failed to start Docker Application Container Engine.
        12月 04 21:45:09 node1.weide.com systemd[1]: docker.service failed.

五、啟動docker程序

啟動docker 守護程序

    systemctl start docker.service

檢視docker版本

    docker version
    [[email protected] yum.repos.d]# docker version
    Client:
     Version:           18.09.0
     API version:       1.39
     Go version:        go1.10.4
     Git commit:        4d60db4
     Built:             Wed Nov  7 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 Nov  7 00:19:08 2018
      OS/Arch:          linux/amd64
      Experimental:     false
    [[email protected] yum.repos.d]# 

檢視docker詳細資訊

    [[email protected] yum.repos.d]# 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

    [[email protected] yum.repos.d]#