• Centos安装Docker的详细安装步骤


    Centos安装docker

    环境:Centos 7

    1.卸载旧的版本

    sudo yum remove docker 
                  docker-client 
                  docker-client-latest 
                  docker-common 
                  docker-latest 
                  docker-latest-logrotate 
                  docker-logrotate 
                  docker-engine
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    1. 需要安装包

      sudo yum install -y yum-utils

    2. 设置镜像仓库

    官方镜像:(比较慢,不推荐)

    sudo yum-config-manager 
    --add-repo 
    https://download.docker.com/linux/centos/docker-ce.repo
    
    • 1
    • 2
    • 3

    阿里镜像仓库 :(推荐)

    sudo yum-config-manager 
    --add-repo 
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    
    • 1
    • 2
    • 3

    4.安装 docker

    安装前先更新yum软件包索引

    yum makecache fast
    
    • 1

    安装docker-ce(社区版-免费的)

    sudo yum install docker-ce docker-ce-cli containerd.io
    
    • 1

    5.启动docker

    sudo systemctl start docker
    
    • 1

    6.如何判断是否成功安装docker 查看版本

    docker version
    
    • 1

    7.查看镜像(是空的)

    docker images
    
    • 1

    8.测试 hello-world
    拉取hello-world

    docker pull hello-world
    
    • 1

    查看镜像(会看到多了个hello-world)

    docker images
    
    • 1

    运行hello-world

    docker run hello-world
    
    • 1

    在这里插入图片描述
    查看运行的容器

    #查看运行的容器
    docker ps 
    #查看所有的容器
    docker ps -a
    
    • 1
    • 2
    • 3
    • 4

    看到多了 hello 的容器
    在这里插入图片描述

    9.移除 hello-world
    如果容器时运行的需要先停止

    #533eaa8e4c79 CONTAINER ID(容器id)
    docker stop 533eaa8e4c79
    
    • 1
    • 2

    在这里插入图片描述
    移除容器

    docker rm 533eaa8e4c79
    
    • 1

    再次查看容器列表会发现容器没有了

    docker ps -a
    
    • 1

    移除hello-world的镜像
    查看镜像

    docker images
    
    • 1

    在这里插入图片描述
    移除镜像

    #移除容器是 rm  移除镜像是 rmi 
    #feb5d9fea6a5 IMAGE ID
    docker rmi feb5d9fea6a5
    
    • 1
    • 2
    • 3

    再次查看镜像发现没有了

    docker images
    
    • 1

    10.因为使用阿里云镜像仓库,可以配置阿里云的镜像加速–速度更快(可选)

    1.搜索阿里云

    2.在阿里云里搜索 – 容器镜像服务

    容器镜像服务
    在这里插入图片描述
    点击立即开通–镜像工具–镜像加速器–选择CentOS

    在这里插入图片描述

    使用CentOS中的代码配置

    1.创建一个目录

    sudo mkdir -p /etc/docker
    
    • 1
    1. 编辑配置文件

      sudo tee /etc/docker/daemon.json <<-‘EOF’
      {
      “registry-mirrors”: [“xxxx替换自己的加速地址”]
      }
      EOF

    3.重启服务

    sudo systemctl daemon-reload
    
    • 1

    4.重启docker

    sudo systemctl restart docker
    
    • 1

    如果需要卸载docker

    1.卸载依赖

     sudo yum remove docker-ce docker-ce-cli containerd.io
    
    • 1

    2.删除文件夹

     sudo rm -rf /var/lib/docker
     sudo rm -rf /var/lib/containerd
    
    • 1
    • 2
  • 相关阅读:
    大数据技术Scala详解
    加密 K8s Secrets 的几种方案
    React中组件通信01——props
    Vscode Clangformat 配置
    Spring系列之beanFactory与ApplicationContext
    楼顶空地适合建造气膜体育馆吗?
    【MySQL】表的约束(二)
    SpringCloud Gateway--网关服务基本介绍和基本原理
    LeetCode每日一题——2609. Find the Longest Balanced Substring of a Binary String
    Seata-AT模式
  • 原文地址:https://blog.csdn.net/m0_54850467/article/details/126326861