欢迎访问 SJsir 圣杰博客

A Linux operation and maintenance engineer's Blogs

Docker安装详解

  Docker 要求 Ubuntu 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的 Ubuntu 版本是否支持 Docker。
    [root@localhost ~]# uname -r
    3.10.0-862.3.2.el7.x86_64

  1.配置docker-ce使用的yum:(使用清华大学镜像源)

    (1)配置yum源:
    [root@localhost ~]# vim /etc/yum.repos.d/Docker.repo
    [docker]
    name=tsinghua-docker
    baseurl=http://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/x86_64/edge/
    enabled=1
    gpgcheck=0
    (2)清理yum源并确认docker版本:
    [root@localhost ~]# yum clean all
    Cleaning repos: base docker epel extras updates
    Cleaning up everything
    Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
    Cleaning up list of fastest mirrors

    [root@localhost ~]# yum list all | grep docker-ce* 
    docker-ce.x86_64                          18.05.0.ce-3.el7.centos      docker
    docker-ce-selinux.noarch                  17.05.0.ce-1.el7.centos      docker
    docker-client.x86_64                      2:1.13.1-63.git94f4240.el7.centos
    docker-client-latest.x86_64               1.13.1-58.git87f2fab.el7.centos
    docker-common.x86_64                      2:1.13.1-63.git94f4240.el7.centos
    docker-compose.noarch                     1.9.0-5.el7                  epel

  2.安装docker-ce:

    [root@localhost ~]# yum install docker-ce
    Loaded plugins: fastestmirror, langpacks
    Repository base is listed more than once in the configuration
    Repository updates is listed more than once in the configuration
    Repository extras is listed more than once in the configuration
    Repository centosplus is listed more than once in the configuration
    Loading mirror speeds from cached hostfile
    Resolving Dependencies
    --> Running transaction check
    ---> Package docker-ce.x86_64 0:18.05.0.ce-3.el7.centos will be installed
    --> Processing Dependency: container-selinux >= 2.9 for package: docker-ce-18.05.0.ce-3.el7.centos.x86_64
    --> Processing Dependency: libcgroup for package: docker-ce-18.05.0.ce-3.el7.centos.x86_64
    --> Processing Dependency: pigz for package: docker-ce-18.05.0.ce-3.el7.centos.x86_64
    --> Processing Dependency: libltdl.so.7()(64bit) for package: docker-ce-18.05.0.ce-3.el7.centos.x86_64
    --> Running transaction check
    ---> Package container-selinux.noarch 2:2.55-1.el7 will be installed
    --> Processing Dependency: policycoreutils-python for package: 2:container-selinux-2.55-1.el7.noarch
    ---> Package libcgroup.x86_64 0:0.41-15.el7 will be installed
    ---> Package libtool-ltdl.x86_64 0:2.4.2-22.el7_3 will be installed
    ---> Package pigz.x86_64 0:2.3.4-1.el7 will be installed
    --> Running transaction check
    ---> Package policycoreutils-python.x86_64 0:2.5-22.el7 will be installed
    --> Processing Dependency: setools-libs >= 3.3.8-2 for package: policycoreutils-python-2.5-22.el7.x86_64
    --> Processing Dependency: libsemanage-python >= 2.5-9 for package: policycoreutils-python-2.5-22.el7.x86_64
    --> Processing Dependency: audit-libs-python >= 2.1.3-4 for package: policycoreutils-python-2.5-22.el7.x86_64
    --> Processing Dependency: python-IPy for package: policycoreutils-python-2.5-22.el7.x86_64
    --> Processing Dependency: libqpol.so.1(VERS_1.4)(64bit) for package: policycoreutils-python-2.5-22.el7.x86_64
    --> Processing Dependency: libqpol.so.1(VERS_1.2)(64bit) for package: policycoreutils-python-2.5-22.el7.x86_64
    --> Processing Dependency: libapol.so.4(VERS_4.0)(64bit) for package: policycoreutils-python-2.5-22.el7.x86_64
    --> Processing Dependency: checkpolicy for package: policycoreutils-python-2.5-22.el7.x86_64
    --> Processing Dependency: libqpol.so.1()(64bit) for package: policycoreutils-python-2.5-22.el7.x86_64
    --> Processing Dependency: libapol.so.4()(64bit) for package: policycoreutils-python-2.5-22.el7.x86_64
    --> Running transaction check
    ---> Package audit-libs-python.x86_64 0:2.8.1-3.el7 will be installed
    ---> Package checkpolicy.x86_64 0:2.5-6.el7 will be installed
    ---> Package libsemanage-python.x86_64 0:2.5-11.el7 will be installed
    ---> Package python-IPy.noarch 0:0.75-6.el7 will be installed
    ---> Package setools-libs.x86_64 0:3.3.8-2.el7 will be installed
    --> Finished Dependency Resolution

    Dependencies Resolved

    ==================================================================================================================
     Package                           Arch              Version                              Repository         Size
    ==================================================================================================================
    Installing:
     docker-ce                         x86_64            18.05.0.ce-3.el7.centos              docker             35 M
    Installing for dependencies:
     audit-libs-python                 x86_64            2.8.1-3.el7                          base               75 k
     checkpolicy                       x86_64            2.5-6.el7                            base              294 k
     container-selinux                 noarch            2:2.55-1.el7                         extras             34 k
     libcgroup                         x86_64            0.41-15.el7                          base               65 k
     libsemanage-python                x86_64            2.5-11.el7                           base              112 k
     libtool-ltdl                      x86_64            2.4.2-22.el7_3                       base               49 k
     pigz                              x86_64            2.3.4-1.el7                          epel               81 k
     policycoreutils-python            x86_64            2.5-22.el7                           base              454 k
     python-IPy                        noarch            0.75-6.el7                           base               32 k
     setools-libs                      x86_64            3.3.8-2.el7                          base              619 k

    Transaction Summary
    ==================================================================================================================
    Install  1 Package (+10 Dependent packages)

    Total download size: 36 M
    Installed size: 156 M
    Is this ok [y/d/N]: y
    Downloading packages:
    (1/11): audit-libs-python-2.8.1-3.el7.x86_64.rpm                                           |  75 kB  00:00:00     
    (2/11): libcgroup-0.41-15.el7.x86_64.rpm                                                   |  65 kB  00:00:00     
    (3/11): container-selinux-2.55-1.el7.noarch.rpm                                            |  34 kB  00:00:00     
    (4/11): libsemanage-python-2.5-11.el7.x86_64.rpm                                           | 112 kB  00:00:00     
    (5/11): libtool-ltdl-2.4.2-22.el7_3.x86_64.rpm                                             |  49 kB  00:00:00     
    (6/11): checkpolicy-2.5-6.el7.x86_64.rpm                                                   | 294 kB  00:00:00     
    (7/11): pigz-2.3.4-1.el7.x86_64.rpm                                                        |  81 kB  00:00:00     
    (8/11): policycoreutils-python-2.5-22.el7.x86_64.rpm                                       | 454 kB  00:00:00     
    (9/11): python-IPy-0.75-6.el7.noarch.rpm                                                   |  32 kB  00:00:00     
    (10/11): setools-libs-3.3.8-2.el7.x86_64.rpm                                               | 619 kB  00:00:00     
    (11/11): docker-ce-18.05.0.ce-3.el7.centos.x86_64.rpm                                      |  35 MB  00:00:06     
    ------------------------------------------------------------------------------------------------------------------
    Total                                                                             5.7 MB/s |  36 MB  00:00:06     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : libcgroup-0.41-15.el7.x86_64                                                                  1/11 
      Installing : audit-libs-python-2.8.1-3.el7.x86_64                                                          2/11 
      Installing : checkpolicy-2.5-6.el7.x86_64                                                                  3/11 
      Installing : libtool-ltdl-2.4.2-22.el7_3.x86_64                                                            4/11 
      Installing : python-IPy-0.75-6.el7.noarch                                                                  5/11 
      Installing : libsemanage-python-2.5-11.el7.x86_64                                                          6/11 
      Installing : setools-libs-3.3.8-2.el7.x86_64                                                               7/11 
      Installing : policycoreutils-python-2.5-22.el7.x86_64                                                      8/11 
      Installing : 2:container-selinux-2.55-1.el7.noarch                                                         9/11 
    setsebool:  SELinux is disabled.
      Installing : pigz-2.3.4-1.el7.x86_64                                                                      10/11 
      Installing : docker-ce-18.05.0.ce-3.el7.centos.x86_64                                                     11/11 
      Verifying  : libcgroup-0.41-15.el7.x86_64                                                                  1/11 
      Verifying  : pigz-2.3.4-1.el7.x86_64                                                                       2/11 
      Verifying  : setools-libs-3.3.8-2.el7.x86_64                                                               3/11 
      Verifying  : policycoreutils-python-2.5-22.el7.x86_64                                                      4/11 
      Verifying  : libsemanage-python-2.5-11.el7.x86_64                                                          5/11 
      Verifying  : 2:container-selinux-2.55-1.el7.noarch                                                         6/11 
      Verifying  : python-IPy-0.75-6.el7.noarch                                                                  7/11 
      Verifying  : libtool-ltdl-2.4.2-22.el7_3.x86_64                                                            8/11 
      Verifying  : docker-ce-18.05.0.ce-3.el7.centos.x86_64                                                      9/11 
      Verifying  : checkpolicy-2.5-6.el7.x86_64                                                                 10/11 
      Verifying  : audit-libs-python-2.8.1-3.el7.x86_64                                                         11/11 

    Installed:
      docker-ce.x86_64 0:18.05.0.ce-3.el7.centos

    Dependency Installed:
      audit-libs-python.x86_64 0:2.8.1-3.el7                checkpolicy.x86_64 0:2.5-6.el7
      container-selinux.noarch 2:2.55-1.el7                 libcgroup.x86_64 0:0.41-15.el7
      libsemanage-python.x86_64 0:2.5-11.el7                libtool-ltdl.x86_64 0:2.4.2-22.el7_3
      pigz.x86_64 0:2.3.4-1.el7                             policycoreutils-python.x86_64 0:2.5-22.el7
      python-IPy.noarch 0:0.75-6.el7                        setools-libs.x86_64 0:3.3.8-2.el7
    Complete!

  3.启动docker:

    [root@localhost ~]# systemctl start docker.service 
    [root@localhost ~]# systemctl status docker.service 
    ● docker.service - Docker Application Container Engine
       Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
       Active: active (running) since Mon 2018-06-11 11:36:12 CST; 15s ago
         Docs: https://docs.docker.com
     Main PID: 7762 (dockerd)
        Tasks: 17
       Memory: 34.9M
       CGroup: /system.slice/docker.service
               ├─7762 /usr/bin/dockerd
               └─7767 docker-containerd --config /var/run/docker/containerd/containerd.toml

    Jun 11 11:36:11 localhost dockerd[7762]: time="2018-06-11T11:36:11+08:00" level=info msg=serving... addres...grpc"
    Jun 11 11:36:11 localhost dockerd[7762]: time="2018-06-11T11:36:11+08:00" level=info msg="containerd succe...inerd
    Jun 11 11:36:11 localhost dockerd[7762]: time="2018-06-11T11:36:11.889644286+08:00" level=info msg="Graph ...onds"
    Jun 11 11:36:11 localhost dockerd[7762]: time="2018-06-11T11:36:11.890274310+08:00" level=info msg="Loadin...art."
    Jun 11 11:36:12 localhost dockerd[7762]: time="2018-06-11T11:36:12.093622799+08:00" level=info msg="Defaul...ress"
    Jun 11 11:36:12 localhost dockerd[7762]: time="2018-06-11T11:36:12.142882609+08:00" level=info msg="Loadin...one."
    Jun 11 11:36:12 JD dockerd[7762]: time="2018-06-11T11:36:12.163531808+08:00" level=info msg="Docker daemon....0-ce
    Jun 11 11:36:12 JD dockerd[7762]: time="2018-06-11T11:36:12.163634872+08:00" level=info msg="Daemon has co...tion"
    Jun 11 11:36:12 JD systemd[1]: Started Docker Application Container Engine.
    Jun 11 11:36:12 JD dockerd[7762]: time="2018-06-11T11:36:12.178367227+08:00" level=info msg="API listen on...sock"
    Hint: Some lines were ellipsized, use -l to show in full.

  ** 4.验证docker的安装:**

    [root@localhost ~]# docker version
    Client:
     Version:      18.05.0-ce
     API version:  1.37
     Go version:   go1.9.5
     Git commit:   f150324
     Built:        Wed May  9 22:14:54 2018
     OS/Arch:      linux/amd64
     Experimental: false
     Orchestrator: swarm

    Server:
     Engine:
      Version:      18.05.0-ce
      API version:  1.37 (minimum version 1.12)
      Go version:   go1.9.5
      Git commit:   f150324
      Built:        Wed May  9 22:18:36 2018
      OS/Arch:      linux/amd64
      Experimental: false
点赞