Files
Kubernetes/Docker/Docs/安装文档/Centos安装Docker.md
offends 103ee74cab
All checks were successful
continuous-integration/drone Build is passing
修改Docker文档目录层级,更新Docker脚本,更新Docker文档
2025-11-06 23:06:28 +08:00

3.3 KiB

本文作者:丁辉

Centos安装Docker

整体来说各系统安装方式都相差不大,那么咱们这里只举例 Centos 安装 Docker 形式

官网安装文档

开始部署

  1. 卸载就办 Docker

    sudo yum remove docker \
        docker-client \
        docker-client-latest \
        docker-common \
        docker-latest \
        docker-latest-logrotate \
        docker-logrotate \
        docker-engine
    
  2. 安装必要依赖

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

    参数解释

    依赖包 作用 为什么需要
    yum-utils 添加和管理 yum 仓库 用于添加 Docker 官方仓库
    device-mapper-persistent-data devicemapper 存储驱动依赖 保证 Docker 底层存储驱动正常运行
    lvm2 提供逻辑卷管理工具 devicemapper 依赖,提供底层块存储支持
  3. 设置存储库

    • 官方源

      yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
      
    • 国内源

      yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
      
    • 清华 TUNA Docker 源

      cat > /etc/yum.repos.d/docker-ce.repo << 'EOF'
      [docker-ce-stable]
      name=Docker CE Stable - $basearch
      baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/$releasever/$basearch/stable
      enabled=1
      gpgcheck=1
      gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg
      
      [docker-ce-stable-debuginfo]
      name=Docker CE Stable - Debuginfo $basearch
      baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/$releasever/debug-$basearch/stable
      enabled=0
      gpgcheck=1
      gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg
      
      [docker-ce-stable-source]
      name=Docker CE Stable - Sources
      baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/$releasever/source/stable
      enabled=0
      gpgcheck=1
      gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg
      EOF
      
  4. 刷新 YUM 缓存

    yum clean all
    yum makecache
    
  5. 安装最新版

    yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
    

    安装特定版本

    • 查看版本库

      yum list docker-ce --showduplicates | sort -r
      
    • 安装

      sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io docker-buildx-plugin docker-compose-plugin
      
  6. 启动

    systemctl enable docker
    systemctl start docker
    

卸载 Docker

  1. 卸载软件包

    yum remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
    
  2. 清理文件

    rm -rf /var/lib/docker
    rm -rf /var/lib/containerd