美文网首页
Centos7下安装docker

Centos7下安装docker

作者: 五岁小孩 | 来源:发表于2022-11-11 15:21 被阅读0次

    Centos7 yum在线安装docker 20.10.2

    参考文献

    查看安装环境

    • 确定CentOS7及以上版本

      $ sudo cat /etc/redhat-release
      CentOS Linux release 7.6.1810 (Core) 
      

    卸载old版本(请参考官方文档)

    $ sudo yum remove docker \
                      docker-client \
                      docker-client-latest \
                      docker-common \
                      docker-latest \
                      docker-latest-logrotate \
                      docker-logrotate \
                      docker-engine
    

    更新yum源

    yum update
    

    安装需要的软件包(请参考官方文档)

    sudo yum install -y yum-utils
    

    安装设置stable镜像仓库

    # 阿里云镜像
    sudo yum-config-manager \
           --add-repo \
           http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    # 官方文档(国外镜像较慢,不建议)
    $ sudo yum-config-manager \
        --add-repo \
        https://download.docker.com/linux/centos/docker-ce.repo
    

    更新yum软件包索引

    sudo yum makecache fast
    

    安装DOCKER CE

    sudo yum install -y docker-ce
    

    启动测试docker

    # 启动
    sudo systemctl start docker
    
    # 验证
    sudo docker version
    
    Client: Docker Engine - Community
     Version:           20.10.2
     API version:       1.41
     Go version:        go1.13.15
     Git commit:        2291f61
     Built:             Mon Dec 28 16:17:48 2020
     OS/Arch:           linux/amd64
     Context:           default
     Experimental:      true
    
    Server: Docker Engine - Community
     Engine:
      Version:          20.10.2
      API version:      1.41 (minimum version 1.12)
      Go version:       go1.13.15
      Git commit:       8891c58
      Built:            Mon Dec 28 16:16:13 2020
      OS/Arch:          linux/amd64
      Experimental:     false
     containerd:
      Version:          1.4.3
      GitCommit:        269548fa27e0089a8b8278fc4fc781d7f65a939b
     runc:
      Version:          1.0.0-rc92
      GitCommit:        ff819c7e9184c13b7c2607fe6c30ae19403a7aff
     docker-init:
      Version:          0.19.0
      GitCommit:        de40ad0
    

    卸载(请参考官方文档)

    # 停止进程
    $ sudo systemctl stop docker
    # 卸载docker
    $ sudo yum remove docker-ce docker-ce-cli containerd.io
    # 删除文件
    $ sudo rm -rf /var/lib/docker
    

    配置阿里云/网易云镜像加速

    • 目的

      未配置镜像加速的情况下,默认镜像下载的远程仓库https://hub.docker.com/,国外仓库地址较慢,

      配置阿里云镜像加速https://cr.console.aliyun.com/cn-hangzhou/new可以提高速度

      如 我的账号

    • 注册账号

      https://dev.aliyun.com/search.html注册账号,可以使用淘宝账号,获取加速地址,然后按阿里云的操作文档执行,大致如下

      sudo mkdir -p /etc/docker
      sudo tee /etc/docker/daemon.json <<-'EOF'
      {
        "registry-mirrors": ["https://xxxx.mirror.aliyuncs.com"]
      }
      EOF
      sudo systemctl daemon-reload
      sudo systemctl restart docker
      
    • 确认是否成功

      docker info
      ...........
       Name: localhost.localdomain
       ID: 3R33:2O4Y:RPEO:6X63:OFQ6:YBIP:CURH:TJUC:6K7U:WZCU:RDQV:DQRI
       Docker Root Dir: /var/lib/docker
       Debug Mode: false
       Registry: https://index.docker.io/v1/
       Labels:
       Experimental: false
       Insecure Registries:
        127.0.0.0/8
       Registry Mirrors:
       ## 表示成功
      https://xxxx.mirror.aliyuncs.com/
       Live Restore Enabled: false
      

    错误

    Loading mirror speeds from cached hostfile
     * base: mirrors.bfsu.edu.cn
     * centos-sclo-rh: mirrors.aliyun.com
     * centos-sclo-sclo: mirrors.aliyun.com
     * extras: mirrors.aliyun.com
     * updates: mirrors.aliyun.com
    No package docker-ce available.
    No package docker-ce-cli available.
    No package containerd.io available.
    Error: Nothing to do
    

    执行 yum update

    未测试

    相关文章

      网友评论

          本文标题:Centos7下安装docker

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