Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

docker安装 - centos

准备工作

  • 确认系统类型

    cat /proc/version
    
  • 进一步查看发行版

    cat /etc/redhat-release
    
    • 确认是centos 7.6
  • 检查并卸载旧版本

    sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
    
    • 如果显示no match,即未安装过,否则进入卸载流程

yum安装

  • 安装yum配置管理工具

    sudo yum install -y yum-utils
    
  • 利用管理工具配置repo仓库

    sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    
  • 安装默认的最新版本

    sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
    
    • 确认安装后,会提示确认Fingerprint,一般是如下官方提供的序列,输入y继续
      060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35
      
  • 查询能安装的所有版本

    yum list docker-ce --showduplicates | sort -r
    
    • 并没有按数字大小排序,17会排在2后面
    • 如果要安装指定版本
      sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io docker-compose-plugin
      
  • 对于centos等RPM系列的发行版,默认是inactive状态,需要手动执行systemctl启动

    sudo systemctl start docker
    
    • 查看启动状态,为active则正常
      sudo systemctl status docker
      
  • 测试默认容器能否运行,若正常打印并退出,则安装成功

    sudo docker run hello-world