美文网首页IT技术分享
Centos7 Docker 安装及阿里云加速配置详解

Centos7 Docker 安装及阿里云加速配置详解

作者: 是龙台呀 | 来源:发表于2019-10-02 12:48 被阅读0次

    系统要求

    Docker官方建议将Docker运行在Linux系统上,当然也可以在其他平台运行,本片博客只介绍在linux系统上的安装方法

    Docker运行在CentOS7.X 版本以上,本文使用阿里云ECS云服务器 CentOS 7.4 版本

    Docker需要安装在64位平台

    Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的CentOS 版本是否支持 Docker

    通过 uname -r 命令查看你当前的内核版本 $ uname -r


    root权限更新yum包

    linux命令不熟悉的同学本文建议使用root权限登陆安装docker,省去很多不必要麻烦

    yum update
    

    卸载旧版本

    列出安装过的docker包

    yum list installed | grep docker
    

    旧版名称是docker , 最新社区版 docker-engine, 目前已改名为docker-ce

    yum -y remove docker docker-common docker-selinux docker-engine
    

    设置yum源

    本文以yum安装为例子进行安装
    安装 yum-utils , 使用 yum-config-manager 工具设置Yum源, 后面两个是 devicemapper驱动依赖

    yum install -y yum-utils device-mapper-persistent-data lvm2
    

    使用阿里源访问

    yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    

    出现以下内容则表示成功

    Loaded plugins: fastestmirror
    adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
    repo saved to /etc/yum.repos.d/docker-ce.repo
    

    查看所有仓库中docker版本

    选择特定版本安装:(此处我们查看社区版 docker-ce)

    yum list docker-ce --showduplicates | sort -r
    
    Loading mirror speeds from cached hostfile
    Loaded plugins: fastestmirror
    docker-ce.x86_64            3:18.09.6-3.el7                     docker-ce-stable
    docker-ce.x86_64            3:18.09.5-3.el7                     docker-ce-stable
    docker-ce.x86_64            3:18.09.4-3.el7                     docker-ce-stable
    docker-ce.x86_64            3:18.09.3-3.el7                     docker-ce-stable
    docker-ce.x86_64            3:18.09.2-3.el7                     docker-ce-stable
    docker-ce.x86_64            3:18.09.1-3.el7                     docker-ce-stable
    docker-ce.x86_64            3:18.09.0-3.el7                     docker-ce-stable
    docker-ce.x86_64            18.06.3.ce-3.el7                    docker-ce-stable
    docker-ce.x86_64            18.06.2.ce-3.el7                    docker-ce-stable
    docker-ce.x86_64            18.06.1.ce-3.el7                    docker-ce-stable
    docker-ce.x86_64            18.06.0.ce-3.el7                    docker-ce-stable
    docker-ce.x86_64            18.03.1.ce-1.el7.centos             docker-ce-stable
    docker-ce.x86_64            18.03.0.ce-1.el7.centos             docker-ce-stable
    docker-ce.x86_64            17.12.1.ce-1.el7.centos             docker-ce-stable
    docker-ce.x86_64            17.12.0.ce-1.el7.centos             docker-ce-stable
    docker-ce.x86_64            17.09.1.ce-1.el7.centos             docker-ce-stable
    docker-ce.x86_64            17.09.0.ce-1.el7.centos             docker-ce-stable
    docker-ce.x86_64            17.06.2.ce-1.el7.centos             docker-ce-stable
    docker-ce.x86_64            17.06.1.ce-1.el7.centos             docker-ce-stable
    docker-ce.x86_64            17.06.0.ce-1.el7.centos             docker-ce-stable
    docker-ce.x86_64            17.03.3.ce-1.el7                    docker-ce-stable
    docker-ce.x86_64            17.03.2.ce-1.el7.centos             docker-ce-stable
    docker-ce.x86_64            17.03.1.ce-1.el7.centos             docker-ce-stable
    docker-ce.x86_64            17.03.0.ce-1.el7.centos             docker-ce-stable
    Available Packages
    

    配置镜像加速器

    阿里云容器镜像服务
    sudo mkdir -p /etc/docker
    sudo tee /etc/docker/daemon.json <<-'EOF'
    {
      "registry-mirrors": ["输入你自己控制台此处的地址"]
    }
    EOF
    sudo systemctl daemon-reload
    sudo systemctl restart docker
    

    安装docker

    此处安装社区版

    yum install docker-ce (这样写默认安装最新版本)
    yum install  docker-ce-<VERSION_STRING> (指定安装版本) 
    例: yum install docker-ce-18.03.1.ce  
    

    安装成功提示信息如下

    Installed:
      docker-ce.x86_64 3:18.09.6-3.el7                                                                                                 
    
    Dependency Installed:
      container-selinux.noarch 2:2.95-2.el7_6                                                                                          
    
    Complete!
    

    启动并加入开机启动

    systemctl start docker     启动  
    systemctl restart docker   重启
    systemctl enable docker    开机启动
    

    docker version 查看docker版本号

    Client:
     Version:           18.09.6
     API version:       1.39
     Go version:        go1.10.8
     Git commit:        481bc77156
     Built:             Sat May  4 02:34:58 2019
     OS/Arch:           linux/amd64
     Experimental:      false
    
    Server: Docker Engine - Community
     Engine:
      Version:          18.09.6
      API version:      1.39 (minimum version 1.12)
      Go version:       go1.10.8
      Git commit:       481bc77
      Built:            Sat May  4 02:02:43 2019
      OS/Arch:          linux/amd64
      Experimental:     false
    

    验证是否安装成功

    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.
        (amd64)
     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
    
    Share images, automate workflows, and more with a free Docker ID:
     https://hub.docker.com/
    
    For more examples and ideas, visit:
     https://docs.docker.com/get-started/
    

    若进行到这一步没有问题的话就说明docker已经安装成功了 。

    接下来我们就可以访问并下载你所需要的镜像,或者使用dockerfile自行构建Docker镜像,部署安装你的应用程序到docker容器中了。

    参考文章

    Centos7 下安装 docker个人总结版

    相关文章

      网友评论

        本文标题:Centos7 Docker 安装及阿里云加速配置详解

        本文链接:https://www.haomeiwen.com/subject/jemxuctx.html