zoukankan      html  css  js  c++  java
  • 【Docker搭建】0. 在CentOS下安装/卸载Docker

    1. 卸载旧版本

    警告:切勿在没有配置 Docker YUM 源的情况下直接使用 yum 命令安装 Docker.

    系统要求
    Docker CE 支持 64 位版本 CentOS 7,并且要求内核版本不低于 3.10。 CentOS 7 满足最低内核的要求,但由于内核版本比较低,部分功能(如 overlay2 存储层驱动)无法使用,并且部分功能可能不太稳定。

    旧版本的 Docker 称为 docker 或者 docker-engine,使用以下命令卸载旧版本:

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

    sudo rm -rf /var/lib/docker

    2.1. 使用 yum 安装、升级

    docker要求Centos系统的内核版本高于3.10,查看内核版本:
    uname -a

    执行以下命令安装依赖包:
    yum install -y yum-utils device-mapper-persistent-data lvm2

    鉴于国内网络问题,强烈建议使用国内源,官方源请在注释中查看。

    执行下面的命令添加 yum 软件源:
    sudo yum-config-manager --add-repo https://mirrors.ustc.edu.cn/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 docker-ce

    或者指定 Docker 版本安装

    查看仓库中所有的docker版本:
    yum list docker-ce.x86_64 --showduplicates |sort -r

    安装指定版本docker:
    sudo yum -y install docker-ce-<VERSION_STRING>

    2.2. 使用脚本自动安装

    在测试或开发环境中 Docker 官方为了简化安装流程,提供了一套便捷的安装脚本,CentOS 系统上可以使用这套脚本安装:

    curl -fsSL get.docker.com -o get-docker.sh
    sudo sh get-docker.sh --mirror Aliyun

    执行这个命令后,脚本就会自动的将一切准备工作做好,并且把 Docker CE 的 Edge 版本安装在系统中。

    3. 测试 Docker 是否安装正确

    运行如下命令:
    service docker start
    docker run hello-world

    若能正常输出如下信息,则说明安装成功

    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    0e03bdcc26d7: Pull complete 
    Digest: sha256:7e02330c713f93b1d3e4c5003350d0dbe215ca269dd1d84a4abc577908344b30
    Status: Downloaded newer image for hello-world:latest
    
    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/
    

    4. 镜像加速

    鉴于国内网络问题,后续拉取 Docker 镜像十分缓慢,强烈建议安装 Docker 之后配置国内镜像加速

    查看 Docker 镜像源
    cat /etc/docker/daemon.json

    如果没有配置则显示
    cat: /etc/docker/daemon.json: No such file or directory

    修改 Docker 镜像源
    sudo vim /etc/docker/daemon.json

    中国官方镜像源:

    {
    "registry-mirrors":["https://registry.docker-cn.com"]
    }
    

    也可以选择网易云镜像源:

    {
    "registry-mirrors": ["http://hub-mirror.c.163.com"]
    }
    

    配置完成后按 ESC 退出输入,输出:wq! 保存退出

    重启 Docker 服务
    systemctl restart docker.service

    查看 Docker 镜像源
    docker info|grep Mirrors -A 1

    若能正常输出如下信息,则说明配置成功

    [root@VM-0-16-centos ~]# docker info|grep Mirrors -A 1
     Registry Mirrors:
      https://registry.docker-cn.com/
    
  • 相关阅读:
    bzoj 4066: 简单题 K-D树
    SAS获取最后一条观测到指定宏
    sas 获取字符串长度实例
    tomcat Error:NB:JAVA_HOME should point to a JDK not a JRE 解决方法
    ODBC数据源管理器-》系统DSN-》没有....Microsoft Access Driver(*mdb,*,accdb)
    SAS DATA ENCODING 解决odbc乱码问题
    sas 日期比较代码备忘
    sas transpose 代码备忘
    svn 红叉叉图标解决方法
    echart line 初始化隐藏legend
  • 原文地址:https://www.cnblogs.com/zilongmao/p/14480618.html
Copyright © 2011-2022 走看看